4
« am: März 09, 2016, 18:11:54 Nachmittag »
Hab die Lösung gefunden:
----
Sub Send_Mail()
Dim OlApp As Object
Dim olDummy As String
Dim EmailTo As String
Dim Betreff As String
Dim Betreff2 As String
Dim IsCreated As Boolean
Dim i As Long
Dim PdfFile As String, Title As String
Worksheets("Master Data").Activate 'Aktiviert das Sheet
EmailTo = Join(Application.Transpose(Worksheets("Master Data").Range("i17:i70").Value), ";") 'Liest die daten aus und setzt ein Semikon als trennung zwischen die Emailadressen
Worksheets("Bid Contacts List").Activate 'Aktiviert nächstes Sheet
Set OlApp = CreateObject("Outlook.Application")
Betreff = Range("B1").Value 'Liest das Thema aus Zelle B1 in der aktuellen Tabelle aus'
Betreff2 = Range("b2").Value 'Liest das Thema aus Zelle B2 in der aktuellen Tabelle aus'
' Define PDF filename
PdfFile = ActiveWorkbook.FullName
i = InStrRev(PdfFile, ".")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = PdfFile & "_" & ActiveSheet.Name & ".pdf"
' Export activesheet as PDF
Worksheets("Opps Summary").Activate 'Aktiviert das Sheet
Worksheets("Project-Timeline").Activate 'Aktiviert das Sheet
Worksheets("ToDo-Liste").Activate 'Aktiviert das Sheet
Worksheets("Report").Activate 'Aktiviert das Sheet
ThisWorkbook.Sheets(Array("Opps Summary", "Project-Timeline", "ToDo-Liste", "Report")).Select
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
With OlApp.CreateItem(0)
Rem Name des Sendekontos in Anführungszeichen
'Set .SendUsingAccount = .Session.Accounts.Item'
Rem Empfänger
.To = EmailTo
Rem Optional Kopie an
.CC = ""
Rem Optional Blindkopie an
.BCC = ""
Rem Email anzeigen zum Einfügen der Signatur
.GetInspector.Display
Rem Dummyzeile für Signatur. Zeile erforderlich
olDummy = .HTMLBody
Rem Betreff
.Subject = Betreff & " | " & Betreff2 & " | " & " Project Update"
Rem Textkörper (Body) im HTML-Format. (1 = Nur-Text, 2 = HTML, 3 = Rich-Text)
.BodyFormat = 2
Rem "
" = Zeilenumbruch-Anweisung (nur bei HTML)
.HTMLBody = "<P STYLE='font-family:Trebuchet MS;font-size:11pt'>Dear Projekt Team" & _
"
" & _
"attached you will find the actually Project Overview of " & _
Betreff & " Project: " & Betreff2 & _
"." & strbody & .HTMLBody
.Attachments.Add PdfFile
Rem Mail sofort senden
Rem .Send
End With
' Delete PDF file
Kill PdfFile
' Quit Outlook if it was created by this code
If IsCreated Then OutlApp.Quit
' Release the memory of object variable
Set OutlApp = Nothing
End With
End Sub
----