Outlook mit VBA steuern: E-Mails automatisch versenden
Lesezeit: 9 Min. | VBA-Programmierung
Mit VBA können Sie Outlook vollständig automatisieren: E-Mails versenden, Serienmails mit Excel-Daten, Posteingang auslesen, Termine erstellen. Dieser Guide zeigt alle wichtigen Techniken mit funktionierenden Code-Templates.
Outlook-Referenz einbinden
Wichtig: Zuerst Outlook-Bibliothek aktivieren!
- VBA-Editor (Alt + F11)
- Extras → Verweise
- Häkchen bei: Microsoft Outlook XX.0 Object Library
- OK
E-Mail erstellen und senden
Einfache E-Mail versenden
Sub EmailVersenden()
Dim outlookApp As New Outlook.Application
Dim mailItem As Outlook.MailItem
Set mailItem = outlookApp.CreateItem(olMailItem)
With mailItem
.To = "[email protected]"
.CC = "[email protected]"
.Subject = "Automatische E-Mail aus Excel"
.Body = "Hallo," & vbCrLf & vbCrLf & _
"dies ist eine automatische E-Mail." & vbCrLf & vbCrLf & _
"Grüße"
.Send ' Oder .Display zum Anzeigen vor Versand
End With
MsgBox "E-Mail versendet!", vbInformation
End Sub
Dim outlookApp As New Outlook.Application
Dim mailItem As Outlook.MailItem
Set mailItem = outlookApp.CreateItem(olMailItem)
With mailItem
.To = "[email protected]"
.CC = "[email protected]"
.Subject = "Automatische E-Mail aus Excel"
.Body = "Hallo," & vbCrLf & vbCrLf & _
"dies ist eine automatische E-Mail." & vbCrLf & vbCrLf & _
"Grüße"
.Send ' Oder .Display zum Anzeigen vor Versand
End With
MsgBox "E-Mail versendet!", vbInformation
End Sub
Tipp: Verwenden Sie
.Display statt .Send zum Testen – E-Mail wird angezeigt, aber nicht versendet!
HTML-formatierte E-Mail
With mailItem
.HTMLBody = "<h1>Überschrift</h1>" & _
"<p>Dies ist <strong>fett</strong> formatiert.</p>" & _
"<ul><li>Punkt 1</li><li>Punkt 2</li></ul>"
End With
.HTMLBody = "<h1>Überschrift</h1>" & _
"<p>Dies ist <strong>fett</strong> formatiert.</p>" & _
"<ul><li>Punkt 1</li><li>Punkt 2</li></ul>"
End With
Anhänge hinzufügen (PDF aus Excel)
Sub EmailMitAnhang()
Dim outlookApp As New Outlook.Application
Dim mailItem As Outlook.MailItem
Dim pdfPfad As String
' Excel als PDF exportieren
pdfPfad = "C:\Temp\Bericht.pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfPfad
' E-Mail mit Anhang
Set mailItem = outlookApp.CreateItem(olMailItem)
With mailItem
.To = "[email protected]"
.Subject = "Ihr Bericht"
.Body = "Anbei der Bericht als PDF."
.Attachments.Add pdfPfad
.Send
End With
' PDF löschen (optional)
Kill pdfPfad
End Sub
Dim outlookApp As New Outlook.Application
Dim mailItem As Outlook.MailItem
Dim pdfPfad As String
' Excel als PDF exportieren
pdfPfad = "C:\Temp\Bericht.pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfPfad
' E-Mail mit Anhang
Set mailItem = outlookApp.CreateItem(olMailItem)
With mailItem
.To = "[email protected]"
.Subject = "Ihr Bericht"
.Body = "Anbei der Bericht als PDF."
.Attachments.Add pdfPfad
.Send
End With
' PDF löschen (optional)
Kill pdfPfad
End Sub
Serienmail mit personalisierten Inhalten
Ziel: E-Mail an alle Kunden in Excel-Liste
Sub Serienmail()
Dim outlookApp As New Outlook.Application
Dim mailItem As Outlook.MailItem
Dim i As Long
Dim lastRow As Long
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
' Spalte A = Name, Spalte B = E-Mail, Spalte C = Betrag
For i = 2 To lastRow
Set mailItem = outlookApp.CreateItem(olMailItem)
With mailItem
.To = Cells(i, 2).Value ' E-Mail aus Spalte B
.Subject = "Rechnung für " & Cells(i, 1).Value
.Body = "Sehr geehrte/r " & Cells(i, 1).Value & "," & vbCrLf & vbCrLf & _
"Ihr Betrag: " & Format(Cells(i, 3).Value, "#,##0.00 €") & vbCrLf & vbCrLf & _
"Mit freundlichen Grüßen"
.Send
End With
' Status in Excel
Cells(i, 4).Value = "Versendet " & Now
Next i
MsgBox lastRow - 1 & " E-Mails versendet!", vbInformation
End Sub
Dim outlookApp As New Outlook.Application
Dim mailItem As Outlook.MailItem
Dim i As Long
Dim lastRow As Long
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
' Spalte A = Name, Spalte B = E-Mail, Spalte C = Betrag
For i = 2 To lastRow
Set mailItem = outlookApp.CreateItem(olMailItem)
With mailItem
.To = Cells(i, 2).Value ' E-Mail aus Spalte B
.Subject = "Rechnung für " & Cells(i, 1).Value
.Body = "Sehr geehrte/r " & Cells(i, 1).Value & "," & vbCrLf & vbCrLf & _
"Ihr Betrag: " & Format(Cells(i, 3).Value, "#,##0.00 €") & vbCrLf & vbCrLf & _
"Mit freundlichen Grüßen"
.Send
End With
' Status in Excel
Cells(i, 4).Value = "Versendet " & Now
Next i
MsgBox lastRow - 1 & " E-Mails versendet!", vbInformation
End Sub
E-Mails aus Posteingang auslesen
Sub PosteingangAuslesen()
Dim outlookApp As New Outlook.Application
Dim ns As Outlook.Namespace
Dim inbox As Outlook.Folder
Dim item As Object
Dim mailItem As Outlook.MailItem
Dim i As Long
Set ns = outlookApp.GetNamespace("MAPI")
Set inbox = ns.GetDefaultFolder(olFolderInbox)
i = 2 ' Startzeile in Excel
For Each item In inbox.Items
If TypeOf item Is Outlook.MailItem Then
Set mailItem = item
Cells(i, 1).Value = mailItem.Subject
Cells(i, 2).Value = mailItem.SenderName
Cells(i, 3).Value = mailItem.ReceivedTime
i = i + 1
End If
Next item
MsgBox "Posteingang ausgelesen!", vbInformation
End Sub
Dim outlookApp As New Outlook.Application
Dim ns As Outlook.Namespace
Dim inbox As Outlook.Folder
Dim item As Object
Dim mailItem As Outlook.MailItem
Dim i As Long
Set ns = outlookApp.GetNamespace("MAPI")
Set inbox = ns.GetDefaultFolder(olFolderInbox)
i = 2 ' Startzeile in Excel
For Each item In inbox.Items
If TypeOf item Is Outlook.MailItem Then
Set mailItem = item
Cells(i, 1).Value = mailItem.Subject
Cells(i, 2).Value = mailItem.SenderName
Cells(i, 3).Value = mailItem.ReceivedTime
i = i + 1
End If
Next item
MsgBox "Posteingang ausgelesen!", vbInformation
End Sub
Termine erstellen
Sub TerminErstellen()
Dim outlookApp As New Outlook.Application
Dim appointment As Outlook.AppointmentItem
Set appointment = outlookApp.CreateItem(olAppointmentItem)
With appointment
.Subject = "Meeting mit Kunde"
.Location = "Raum 203"
.Start = DateSerial(2026, 1, 15) + TimeSerial(14, 0, 0) ' 15.01.2026 14:00
.Duration = 60 ' Minuten
.ReminderSet = True
.ReminderMinutesBeforeStart = 15
.Body = "Agenda: Projektplanung"
.Save
End With
MsgBox "Termin erstellt!", vbInformation
End Sub
Dim outlookApp As New Outlook.Application
Dim appointment As Outlook.AppointmentItem
Set appointment = outlookApp.CreateItem(olAppointmentItem)
With appointment
.Subject = "Meeting mit Kunde"
.Location = "Raum 203"
.Start = DateSerial(2026, 1, 15) + TimeSerial(14, 0, 0) ' 15.01.2026 14:00
.Duration = 60 ' Minuten
.ReminderSet = True
.ReminderMinutesBeforeStart = 15
.Body = "Agenda: Projektplanung"
.Save
End With
MsgBox "Termin erstellt!", vbInformation
End Sub
Sicherheitswarnung umgehen
Problem: Outlook zeigt Sicherheitswarnung bei automatischem Versand.
Lösungen:
1. Redemption Library (empfohlen)
Kostenlose Library, umgeht Sicherheitsprompt legal.
Download: redemption.dll
Dim safeMailItem As Redemption.SafeMailItem
Set safeMailItem = CreateObject("Redemption.SafeMailItem")
safeMailItem.Item = mailItem
safeMailItem.Send
Set safeMailItem = CreateObject("Redemption.SafeMailItem")
safeMailItem.Item = mailItem
safeMailItem.Send
2. Outlook Trust Center (für Entwickler)
Outlook → Datei → Optionen → Trust Center → Makroeinstellungen → "Warnung für digital signierte Makros deaktivieren"
Code-Template zum Download
Vollständiges Modul mit allen Funktionen:
' Modul: modOutlookAutomation
Option Explicit
Sub SendSimpleEmail(ToAddress As String, Subject As String, Body As String)
Dim outlookApp As New Outlook.Application
Dim mailItem As Outlook.MailItem
Set mailItem = outlookApp.CreateItem(olMailItem)
With mailItem
.To = ToAddress
.Subject = Subject
.Body = Body
.Send
End With
End Sub
Sub SendEmailWithAttachment(ToAddress As String, FilePath As String)
Dim outlookApp As New Outlook.Application
Dim mailItem As Outlook.MailItem
Set mailItem = outlookApp.CreateItem(olMailItem)
With mailItem
.To = ToAddress
.Subject = "Dokument"
.Body = "Anbei das Dokument."
.Attachments.Add FilePath
.Send
End With
End Sub
Option Explicit
Sub SendSimpleEmail(ToAddress As String, Subject As String, Body As String)
Dim outlookApp As New Outlook.Application
Dim mailItem As Outlook.MailItem
Set mailItem = outlookApp.CreateItem(olMailItem)
With mailItem
.To = ToAddress
.Subject = Subject
.Body = Body
.Send
End With
End Sub
Sub SendEmailWithAttachment(ToAddress As String, FilePath As String)
Dim outlookApp As New Outlook.Application
Dim mailItem As Outlook.MailItem
Set mailItem = outlookApp.CreateItem(olMailItem)
With mailItem
.To = ToAddress
.Subject = "Dokument"
.Body = "Anbei das Dokument."
.Attachments.Add FilePath
.Send
End With
End Sub
Fazit
Outlook-Automation spart Stunden bei Routineaufgaben:
- ✅ Automatischer E-Mail-Versand
- ✅ Serienmails mit Excel-Daten
- ✅ PDF-Anhänge aus Excel
- ✅ Posteingang auslesen
- ✅ Termine automatisch erstellen