Hi. I have put together the below script for batch printing email pdf attachments. I get hundreds of emails which all have the same name as the attachment "Tax Invoice" which is why I have inserted the incrementer option to save each attachment as "Tax Invoice1,2,3 etc". My problem is when I run the macro it doesn't print all the emails at once, only maybe half at a time and then when I go to run it again it starts the number sequence again from 1,but since there is a file already named this it won't print. Is there something in my script that is stoping the macro from primitive the all the emails?
Public Sub PrintAttachments()
Dim Inbox As MAPIFolder
Dim Item As MailItem
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim Filenameincrementer As Integer
Filenameincrementer = 1
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders.Item("..To Print")
Set Printed = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders.Item(".Printed")
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
FileName = "C:\Temp\" & Atmt.FileName & Filenameincrementer
Atmt.SaveAsFile FileName
Shell """C:\Program Files\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"" /h /p """ + FileName + """", vbHide
Filenameincrementer = Filenameincrementer + 1
Next
Item.Move Printed
Next
Set Inbox = Nothing
End Sub
Public Sub PrintAttachments()
Dim Inbox As MAPIFolder
Dim Item As MailItem
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim Filenameincrementer As Integer
Filenameincrementer = 1
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders.Item("..To Print")
Set Printed = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders.Item(".Printed")
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
FileName = "C:\Temp\" & Atmt.FileName & Filenameincrementer
Atmt.SaveAsFile FileName
Shell """C:\Program Files\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"" /h /p """ + FileName + """", vbHide
Filenameincrementer = Filenameincrementer + 1
Next
Item.Move Printed
Next
Set Inbox = Nothing
End Sub