Hi,
somehow I have a weird issue here. I just set up my first macro which generates some emails out of a list. The macro works actually pretty good, however as soon as I close outlook it doesnt work correctly anymore.
The macro should (in this example) generate three emails and save them in the template folder. As long as outlook is running this is working, however if outlook is closed two emails are saved in the template folder and one email is saved in the inbox folder (see screenshots).
Does anybody have a solution for that? highly appreciated!
Code, File, Screenshots, pls see attached!
Option Explicit
Sub emails_erstellen()
Dim i As Long
Dim app As Outlook.Application
Dim mail As Outlook.MailItem
With ActiveSheet
'Outlook starten
Set app = CreateObject("Outlook.Application")
'For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
'E-Mail Aufrufen
Set mail = app.CreateItem(olMailItem)
'E-Mail Eigenschaften
mail.To = .Cells(i, 4)
mail.Subject = "Unternehmen | unser Telefongespräch"
mail.Body = .Cells(i, 1) & " " & .Cells(i, 2)
'E-Mail: Anhang hinzufuegen (IF-Struktur)
If .Cells(i, 5).Value = "x" Then
mail.Attachments.Add ThisWorkbook.Path & "\test.txt"
End If
'E-Mail in Entwurf abspeichern
mail.Save
Next i
End With
Bookmarks