Gestern bekam ich eine Anfrage, ob man eine E-Mail aus Excel versenden kann in der das Dokument als Anhang eingefügt ist.
Zu dieser Anforderung kann man folgenden Code verwenden:
Sub Mailversand() Dim Nachricht As Object, OutlookApplication As Object Set OutlookApplication = CreateObject("Outlook.Application") Dim Anhang As String Anhang = ThisWorkbook.FullNameSet Nachricht = OutlookApplication.CreateItem(0)With Nachricht .To = "mailadresse@domain.tld".Subject = "Betreff " .attachments.Add Anhang.Body = "Mailtext" & vbCrLf & vbCrLf .Display'.Mail.Send End With Set OutlookApplication = Nothing Set Nachricht = Nothing End Sub
Wenn man das Apostroph vor dem Befehl “.Mail.Send” entfernt, wird die Mail direkt versandt.
Hallo und vielen Dank. Mögen potentielle Auftraggeber auf diesem Wege auf dich aufmerksam werden. Verdient hast du’s und die dann hoffentlich auch.