Gruppe
Extern
Bereich
Outlook
Thema
Mehrfachauswahl per Outlook versenden
Problem
Eine Mehrfachauswahl aus der nebenstehenden Tabelle soll über Outlook versandt werden. Die Einträge sind mit einem Vorspann untereinander anzuordnen.
Lösung
Geben Sie den nachfolgenden Code in ein Standardmodul ein und weisen Sie ihn einer Schaltfläche zu.
StandardModule: Modul1
Sub SendMessage()
Dim oOL As Object
Dim oOLMsg As Object
Dim oOLRecip As Object
Dim rng As Range, oCell As Range
Dim sAddress As String, sTxt As String
sAddress = "hans@herber.de"
sTxt = "Erste Zeile" & vbLf & "Zweite Zeile" & vbLf
For Each rng In Selection.Areas
sTxt = sTxt & vbLf
For Each oCell In rng.Cells
sTxt = sTxt & oCell.Text & vbLf
Next oCell
Next rng
Set oOL = CreateObject("Outlook.Application")
Set oOLMsg = oOL.CreateItem(0)
With oOLMsg
Set oOLRecip = .Recipients.Add(sAddress)
.Subject = "Dies ist ein Outlook-Test"
.Body = sTxt
.Send
End With
oOLRecip.Resolve
Set oOLRecip = Nothing
Set oOLMsg = Nothing
Set oOL = Nothing
End Sub