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.
Compress All Emails in a Folder into a Zip File
- For a start, launch Outlook VBA editor via “Alt + F11”.
- 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 Next 'Create a new ZIP file varZipFile = "E:\" & objFolder.Name & " Emails.zip" 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")) Loop On Error GoTo 0 'Delete the temp folder Set objFileSystem = CreateObject("Scripting.FileSystemObject") objFileSystem.DeleteFolder Left(varTempFolder, Len(varTempFolder) - 1) End If End Sub
- Afterwards, click “F5” key button to run this macro.
- Later, in popup dialog box, select the source Outlook folder and click “OK”.
- 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.
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 www.datanumen.com