How to Quickly Compress All Emails in an Outlook Folder into a Zip File

Some users would like to compress all the emails in an Outlook folder into a zip file. Though there is not such a direct function, you can utilize the VBA code exposed in this article to realize it rapidly.

To zip all emails in an Outlook folder, you have to first export them to local drive one by one, and then use “Send to” > “Compressed (zipped) folder” feature. With no doubt, by this means, it is too tedious. Therefore, so as to help you realize it in one go, in the followings, we will teach you another method. It will teach you how to get it with VBA code. If you aren’t familiar with VBA, you can refer to “How to Run VBA Code in Your Outlook” in the meantime.

Send to Compressed (zipped) folder

Compress All Emails in a Folder into a Zip File

  1. For a start, launch Outlook VBA editor via “Alt + F11”.
  2. Then, copy and paste the VBA code into a module.
Sub ZipAllEmailsInAFolder()
    Dim objFolder As Outlook.Folder
    Dim objItem As Object
    Dim objMail As Outlook.MailItem
    Dim strSubject As String
    Dim varTempFolder As Variant
    Dim varZipFile As Variant
    Dim objShell As Object
    Dim objFileSystem As Object
    'Select an Outlook Folder
    Set objFolder = Outlook.Application.Session.PickFolder
    If Not (objFolder Is Nothing) Then
       'Create a temp folder
       varTempFolder = "E:\" & objFolder.Name & Format(Now, "YYMMDDHHMMSS")
       MkDir (varTempFolder)
       varTempFolder = varTempFolder & "\"
       'Save each email as msg file
       For Each objItem In objFolder.Items
           If TypeOf objItem Is MailItem Then
              Set objMail = objItem
              strSubject = objMail.Subject
              strSubject = Replace(strSubject, "/", " ")
              strSubject = Replace(strSubject, "\", " ")
              strSubject = Replace(strSubject, ":", "")
              strSubject = Replace(strSubject, "?", " ")
              strSubject = Replace(strSubject, Chr(34), " ")
              objMail.SaveAs varTempFolder & strSubject & ".msg", olMSG
           End If
       'Create a new ZIP file
       varZipFile = "E:\" & objFolder.Name & ""
       Open varZipFile For Output As #1
       Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
       Close #1
       'Add the exported msg files to the ZIP file
       Set objShell = CreateObject("Shell.Application")
       objShell.NameSpace(varZipFile).CopyHere objShell.NameSpace(varTempFolder).Items

       On Error Resume Next
       Do Until objShell.NameSpace(varZipFile).Items.Count = objShell.NameSpace(varTempFolder).Items.Count
          Application.Wait (Now + TimeValue("0:00:01"))
       On Error GoTo 0
       'Delete the temp folder
       Set objFileSystem = CreateObject("Scripting.FileSystemObject")
       objFileSystem.DeleteFolder Left(varTempFolder, Len(varTempFolder) - 1)
    End If
End Sub

VBA Code - Compress All Emails in a Folder into a Zip File

  1. Afterwards, click “F5” key button to run this macro.
  2. Later, in popup dialog box, select the source Outlook folder and click “OK”.Select Outlook Folder
  3. When macro finishes, a Windows folder will be displayed, in which there is a new zip file which contains all the emails from the selected Outlook folder, as shown in the following figure.New Zip File

Handle Troublesome Outlook File Corruption

Among all the common problems in Outlook, unquestionably, Outlook damage is the most serious one. However, in reality, such issues can take place at any time.  Therefore, if you are a regular Outlook user, you need to make regular backups of Outlook data. Plus, it is prudent to get hold of a robust Outlook repair utility, 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 sql fix and outlook repair software products. For more information visit

4 responses to “How to Quickly Compress All Emails in an Outlook Folder into a Zip File”

  1. Thanks for the good writeup. It in reality used to be a leisure account it. Look complicated to far delivered agreeable from you! However, how can we communicate?

  2. I conceive this site holds very great pent subject material posts.

  3. Shriley. Thanks for the post. Very interesting. I am using this for to ask you about the “How to Export an Outlook Folder with All Subfolders & Items to a Windows Folder”. The post itself does not allow me to reply.
    I am trying to use it for incremental back-up but the code crashes when a folder has been found in the Windows folder.
    Could you please help me to code the “incremental” functions?

Leave a Reply

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