Consulting

Results 1 to 2 of 2

Thread: Batch print all attachments VBA

  1. #1

    Batch print all attachments VBA

    Hello,

    So I wanted a VBA code that can print every pdf from multiple emails and I found this code that works perfectly. My question is, is it possible to add the format of paper I want to print on (Letter / 8,5 x 11) to the code below?

    Thank you.

    Sub BatchPrintAllAttachmentsinMultipleEmails()
    Dim objFileSystem As Object
    Dim strTempFolder As String
    Dim objSelection As Outlook.Selection
    Dim objItem As Object
    Dim objMail As Outlook.MailItem
    Dim objAttachments As Outlook.Attachments
    Dim objAttachment As Outlook.Attachment
    Dim objShell As Object
    Dim objTempFolder As Object
    Dim objTempFolderItem As Object
    Dim strFilePath As String

    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    strTempFolder = objFileSystem.GetSpecialFolder(2).Path & "\Temp for Attachments " & Format(Now, "YYYY-MM-DD_hh-mm-ss")
    'Create a new temp folder
    MkDir (strTempFolder)

    Set objSelection = Outlook.Application.ActiveExplorer.Selection

    For Each objItem In objSelection
    If TypeOf objItem Is MailItem Then
    Set objMail = objItem
    Set objAttachments = objMail.Attachments

    'Save all the attachments in the temp folder
    For Each objAttachment In objAttachments
    strFilePath = strTempFolder & "" & objAttachment.FileName
    objAttachment.SaveAsFile (strFilePath)

    'Print all the files in the temp folder
    Set objShell = CreateObject("Shell.Application")
    Set objTempFolder = objShell.NameSpace(0)
    Set objTempFolderItem = objTempFolder.ParseName(strFilePath)
    objTempFolderItem.InvokeVerbEx ("print")
    Next objAttachment
    End If
    Next
    End Sub

  2. #2
    The short answer is no and you have made no allowance for the fact that e.g. graphics in messages are treated as separate attachments. This could result in a mess unless you tie down what attachments need to be printed; and if you do that it is probably better to load the attachments into their native applications, make whatever changes you need then print them from there. This should work for Office documents, others may not be so straightforward.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •