![]() If you are only printing PDF files, you can remove the Case statement that prints Excel and Word files. To the best of my knowledge, both Acrobat Standard and Acrobat Pro include OLE support.Ĭhange the Select Case code in the PrintAttachments macro to the following. ![]() I tested it with Acrobat X but it should work with any version of Acrobat. This will not work with Reader, you need to own Acrobat. To use Acrobat's object model, you need to set a reference to Acrobat in the VB Editor's Tool, References dialog box. If you own Adobe Acrobat, you can set the pages you want to print and "shrink to fit" using the PrintPages function of Acrobat:įunction PrintPages(nFirstPage As Long, nLastPage As Long, nPSLevel As Long, bBinaryOk As Long, bShrinkToFit As Long) As Boolean SFileType = LCase$(Right$(oAtt.filename, 4)) Private Sub PrintAttachmentsSelectedMsg() Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias _ ![]() ' Based on macro written by Michael Bauer, This version will work either one or more selected items. To convert the macro to print attachments on a selected messages as needed, you need to remove the startup and itemadd macros and either use code that picks up the selected item or loops through the selected items. Set objDestFolder = Session.Folders("mailbox name")._ Sub MovePrintedMail(oMail As Outlook.MailItem) Don't forget to change the mailbox name, using the name as it appears in the Folder list (it's your email address in newer versions of Outlook). This macro assumes the "move to folder" is a subfolder of the Inbox. In this example, I'm adding a new macro and calling it from the ItemAdd macro, after the PrintAttachments macro is called.Īt the end of the module, after the PrintAttachments macro, add the move macro. If you want to print the attachment then move the message to another folder, you'll either need to add the move code to the ItemAdd macro or add another macro and call it from the ItemAdd macro. ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0 SFileType = LCase$(right$(oAtt.FileName, 4)) ' This code looks at the last 4 characters in a filename Private Sub PrintAttachments(oMail As Outlook.MailItem) Private Sub Items_ItemAdd(ByVal Item As Object) Set Folder = Ns.GetDefaultFolder(olFolderInbox) Set Ns = Application.GetNamespace("MAPI") Private WithEvents Items As Outlook.Items "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _īyVal lpFile As String, ByVal lpParameters As String, _īyVal lpDirectory As String, ByVal nShowCmd As Long) As Long Private Declare Function ShellExecute Lib "shell32.dll" Alias _ ' //' use Declare PtrSafe Function with 64-bit Outlook This starts the macro without the need to restart Outlook. ![]() Edit the code as needed then click in the Application_Startup() macro and press Run button (F8). To use, open the VBA editor using Alt+F11 and paste the following code into ThisOutlookSession. Original code was written for 32-bit Outlook and 3 character file extensions. Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias _ Print received attachments immediately code sample To use the macro with 64-bit Outlook, you need to add PtrSafe to Declare: The code looks at the last 4 characters, including the period and will work as long as you use 4 characters in each extension we want to check.Ĭase "xlsx", "docx", ".pdf", ".doc", ".xls"
0 Comments
Leave a Reply. |