Mister H
09-14-2012, 11:27 AM
Hi All: :hi:
Once again I seek the help of the VBA Experts. I am trying to modify a code that I want to use to print the PDF attachments in a specified folder. It is SORT of working. Here is the code:
Public Sub Print_Email_PDF_Attachments()
Dim Inbox As MAPIFolder
Dim Item As mailItem
Dim Atmt As Attachment
Dim Filename As String
Dim i As Integer
'Folder " 1) Faxes (PDFs) TO BE PRINTED " needs to be created under the User
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders.Item("1) Faxes (PDFs) TO BE PRINTED")
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
' This line creates specific file names for each attachment with the Date/time received and
' uses a counter so the chance of file name duplication is reduced.
'make sure the folder " C:\PDF Faxes " exists
Filename = "C:\PDF Faxes\" & Format(Item.ReceivedTime, "mm-dd-yyyy_hh-nn-ss") & "-" & Right(Format(Timer, "#0.00"), 2) & "_" & Atmt.Filename
'This line saves the attachments.
Atmt.SaveAsFile Filename
'please change the program folder accordingly if the Acrobat Reader is not installed on drive C:
'Shell """C:\Program Files\Adobe\Reader 8.0\Reader\acrord32.exe"" /h /p """ + FileName + """", vbHide
Shell """C:\Program Files\Adobe\Reader\acrord32.exe"" /h /p """ + Filename + """", vbHide
'Is there more then 1 attachment? If so then goto the next one
Next
'Now what do you want to do with the email message?
'Item.Delete '‘remove this line if you don’t want the email be deleted automatically
Item.Move Outlook.Session.GetDefaultFolder(olFolderInbox).Parent.Folders.Item("2) Faxes (PDFs) ALREADY PRINTED")
'Mark the email as Read
Item.UnRead = False
Next
Set Inbox = Nothing
End Sub
Problems: If I have 3 emails in the folder:
" 1) Faxes (PDFs) TO BE PRINTED " it prints the attachments of 2 of the files but not the 3rd one. Another problem is that the files remain on my C drive and Adobe is left open.
Can this code be modified so that:
1) It cycles through ALL emails in the specified folder and prints all the attachments and then moves all the emails to the other folder
2) I do not wish to keep the files that were saved to my folder C:\PDF Faxes How can I delete all the files after they are printed.
3) Can Adobe be closed and then the code return me to Outlook?
* Just thinking about the future is it simple to change the code so it will print ALL attachments regardless of type (excel, word and adobe)
THANKS to anyone that can assist.
Mark
Once again I seek the help of the VBA Experts. I am trying to modify a code that I want to use to print the PDF attachments in a specified folder. It is SORT of working. Here is the code:
Public Sub Print_Email_PDF_Attachments()
Dim Inbox As MAPIFolder
Dim Item As mailItem
Dim Atmt As Attachment
Dim Filename As String
Dim i As Integer
'Folder " 1) Faxes (PDFs) TO BE PRINTED " needs to be created under the User
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders.Item("1) Faxes (PDFs) TO BE PRINTED")
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
' This line creates specific file names for each attachment with the Date/time received and
' uses a counter so the chance of file name duplication is reduced.
'make sure the folder " C:\PDF Faxes " exists
Filename = "C:\PDF Faxes\" & Format(Item.ReceivedTime, "mm-dd-yyyy_hh-nn-ss") & "-" & Right(Format(Timer, "#0.00"), 2) & "_" & Atmt.Filename
'This line saves the attachments.
Atmt.SaveAsFile Filename
'please change the program folder accordingly if the Acrobat Reader is not installed on drive C:
'Shell """C:\Program Files\Adobe\Reader 8.0\Reader\acrord32.exe"" /h /p """ + FileName + """", vbHide
Shell """C:\Program Files\Adobe\Reader\acrord32.exe"" /h /p """ + Filename + """", vbHide
'Is there more then 1 attachment? If so then goto the next one
Next
'Now what do you want to do with the email message?
'Item.Delete '‘remove this line if you don’t want the email be deleted automatically
Item.Move Outlook.Session.GetDefaultFolder(olFolderInbox).Parent.Folders.Item("2) Faxes (PDFs) ALREADY PRINTED")
'Mark the email as Read
Item.UnRead = False
Next
Set Inbox = Nothing
End Sub
Problems: If I have 3 emails in the folder:
" 1) Faxes (PDFs) TO BE PRINTED " it prints the attachments of 2 of the files but not the 3rd one. Another problem is that the files remain on my C drive and Adobe is left open.
Can this code be modified so that:
1) It cycles through ALL emails in the specified folder and prints all the attachments and then moves all the emails to the other folder
2) I do not wish to keep the files that were saved to my folder C:\PDF Faxes How can I delete all the files after they are printed.
3) Can Adobe be closed and then the code return me to Outlook?
* Just thinking about the future is it simple to change the code so it will print ALL attachments regardless of type (excel, word and adobe)
THANKS to anyone that can assist.
Mark