My loop is not working! it says "the item has been moved or deleted". Is the For next loop not applicable to mail and attach files? Or is it something else that's not working.
I've also attached a screenshot of my workbook. Please someone help!
Sub Print_en_save()
Dim sh As Worksheet
Dim saveAs As String
Dim savePath As String
Dim outLookApp As Object
Dim outLookMailItem As Object
Dim myAttachments As Object
Set sh = ActiveSheet
Dim i As Integer
For i = 1 To 6
Cells(1, "T").Value = i
' De saveas range moet altijd een unieke naam zijn
saveAs = sh.Range("T19").Value
' De saveas path moet zijn waar het wordt opgeslagen + \
savePath = sh.Range("T18").Value
'Save As PDF
ChDir savePath
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveAs, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
Next i
Set sh = ActiveSheet
Set outLookApp = CreateObject("Outlook.application")
Set outLookMailItem = outLookApp.CreateItem(0)
Set myAttachments = outLookMailItem.Attachments
With outLookMailItem
For i = 1 To 6
Cells(1, "T").Value = i
.To = sh.Range("T8").Value
.Subject = sh.Range("T21").Value
.Body = sh.Range("T22").Value
.Attachments.Add sh.Range("T24").Value
.Send
Next i
End With
End Sub
Excel sheet.png
Bookmarks