Hi all,
I have the following VBA Code and an Excel file from which the VBA get his data (25 lines).
My Problem is, that I do not have an attachment for every line. In this case the VBA will not finish.
Sub Excel_Serial_Mail()
Dim objOLOutlook As Object
Dim objOLMail As Object
Dim lngMailNr As Long
Dim lngZaehler As Long
Set objOLOutlook = CreateObject("Outlook.Application")
lngMailNr = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
For lngZaehler = 2 To lngMailNr
If Cells(lngZaehler, 2) <> "" Then
Set objOLMail = objOLOutlook.CreateItem(olMailItem)
With objOLMail
.To = Cells(lngZaehler, 3)
.CC = Cells(lngZaehler, 4)
.BCC = "test@test.com"
.SentOnBehalfOfName = "test@test.com"
.Subject = Cells(lngZaehler, 6)
.BodyFormat = olFormatPlain
.Body = Cells(lngZaehler, 7)
Dim strAttachmentPfad1 As String
strAttachmentPfad1 = ActiveSheet.Cells(lngZaehler, 8)
.Attachments.Add strAttachmentPfad1
.Display
End With
Set objOLMail = Nothing
End If
Next lngZaehler
Set objOLOutlook = Nothing
Exit Sub
End Sub
Bookmarks