ich habe folgenden Code im Internet gefunden, mit dem man per VBA eine HTML-Email via Outlook versenden kann.
Leider bekomme ich den Code selbst nicht zum Laufen (er steht in einem Modul).
Kann mir jemand sagen, ob hier noch etwas fehlt oder was ich tun muss, damit die Email erstellt wird ?
Ziel ist es, nicht die ganze Tabelle, sondern nur bestimmte Informationen aus der Tabelle heraus zu versenden.
Option Explicit
Sub Mail_erstellen(strAdresse As String)
Dim strQuelle As String
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim strSubject
strQuelle = "$B$1:$R$58"
strSubject = Range("B1")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = strAdresse
.CC = ""
.BCC = ""
.Subject = strSubject
.HTMLBody = Uebersetzung(strQuelle)
'.Send
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Public Function Uebersetzung(strQuelle As String)
Dim objFSO As Object
Dim objInhalt As Object
Dim strTempDatei As String
strTempDatei = "C:\" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
With ActiveWorkbook.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=strTempDatei, _
Sheet:=ActiveSheet.Name, _
Source:=strQuelle, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInhalt = objFSO.GetFile(strTempDatei).OpenAsTextStream(1, -2)
Uebersetzung = objInhalt.ReadAll
objInhalt.Close
Set objInhalt = Nothing
Set objFSO = Nothing
Kill strTempDatei
End Function
Vielen Dank Euch im Voraus für jeden Tipp !Viele Grüße,
Markus