How to Quickly Print All Files in a Zip Attachment of an Outlook Email

Many users hope to print all the files compressed in a zip attachment of an Outlook email without troublesomely saving and decompressing the zip attachment. Hence, this article will introduce a much more effective means to realize it.

When you want to print a zip attachment, you may be used to pitching on it and clicking “Quick Print” button in the ribbon. However, by this means, Outlook still will ask you to save and unzip it firstly. If you would like to avoid these annoying steps, you can use the following VBA code.

Quickly Print All Files in a Zip Attachment of an Outlook Email

Print All Files in a Zip Attachment of an Email

  1. To begin with, start your Outlook application.
  2. Then, get access to Outlook VBA editor by following the steps shown in the article – “How to Run VBA Code in Your Outlook”.
  3. Next, you can open the “ThisOutlookSession” project or an unused module.
  4. Subsequently, copy and paste the VBA code below.
Dim objShell As Object
Dim objFileSystem As Object

Sub PrintAllFilesInZipAttachment ()
    Dim objAttachmentSelection As Outlook.AttachmentSelection
    Dim objAttachment, objTempAttachment As Outlook.Attachment
    Dim strTempFolder As String
    Dim strSavingPath As String
    Dim objTempMail As Outlook.MailItem
    Dim strFileName As String
 
    'Get selected attachment
    Set objAttachmentSelection = Outlook.Application.ActiveExplorer.AttachmentSelection
    Set objAttachment = objAttachmentSelection.Item(1)

    If Right(LCase(objAttachment.filename), 3) = "zip" Then
 
       'Save & Unzip the zip attachment
       Set objShell = CreateObject("Shell.Application")
       Set objFileSystem = CreateObject("Scripting.FileSystemObject")
       strTempFolder = objFileSystem.GetSpecialFolder(2).Path & "\Unzip" & Format(Now, "yyyymmddhhmmss")
       MkDir (strTempFolder)
 
       strSavingPath = strTempFolder & "\" & objAttachment.filename
       objAttachment.SaveAsFile (strSavingPath)
       objShell.NameSpace((strTempFolder)).CopyHere objShell.NameSpace((strSavingPath)).Items
  
       'Attach Unzipped files to a temp mail
       Set objTempMail = Outlook.Application.CreateItem(olMailItem)
       objTempMail.Display
       strFileName = Dir(strTempFolder & "\")
 
       While Len(strFileName) > 0
             objTempMail.Attachments.Add (strTempFolder & "\" & strFileName)
             strFileName = Dir()
       Wend
 
       'Print all attachments of the temp email
       Call PrintFiles(objTempMail)
 
       objTempMail.Close olDiscard
 
       objFileSystem.DeleteFolder (strTempFolder)
    End If
End Sub

Sub PrintFiles(ByVal objMail As Outlook.MailItem)
    Dim objAttachment As Outlook.Attachment
    Dim strTempFolder, strFilePath As String
    Dim objTempFolder As Object
    Dim objTempFolderItem As Object
 
    strTempFolder = objFileSystem.GetSpecialFolder(2).Path & "\TEMP" & Format(Now, "yyyymmddhhmmss")
    MkDir (strTempFolder)
 
    'Print all attachments
    For Each objAttachment In objMail.Attachments
        If Right(LCase(objAttachment.filename), 3) <> "zip" Then
           strFilePath = strTempFolder & "\" & objAttachment.filename
           objAttachment.SaveAsFile (strFilePath)
 
           Set objShell = CreateObject("Shell.Application")
           Set objTempFolder = objShell.NameSpace(0)
           Set objTempFolderItem = objTempFolder.ParseName(strFilePath)
           objTempFolderItem.InvokeVerbEx ("print")
        End If
    Next
 
    objFileSystem.DeleteFolder (strTempFolder)
End Sub

VBA Code - Print All Files in a Zip Attachment of an Email

  1. After that, close the current VBA editor window.
  2. Later, head to Outlook Options to add the new macro to Quick Access Toolbar.
  3. Finally, you can take a shot:
  • First, select a zip attachment of an email.
  • Then, click the macro in Quick Access Toolbar.Run Macro through Quick Access Toolbar
  1. At once, the files compresses in the selected zip attachment will be printed.

Back up Outlook Data Files

You may have discovered that Outlook is prone to corruption. Once Outlook gets corrupted, your Outlook data will be lost. Hence, it is important to make a regular backup of your Outlook data files, such that you can easily retrieve Outlook data via backups. But, if you find that the backup is several weeks old and ineffective, you have no choice but to recur to a reliable and experienced PST recovery tool, such as DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including damaged mdf and outlook repair software products. For more information visit www.datanumen.com

Leave a Reply

Your email address will not be published. Required fields are marked *