When you receive an attachment in “.zip” file extension, if you want to unzip them, in general, you should save and unzip them in local drive. But many hope to unzip them directly in Outlook. This article will teach you how to get it via VBA.
You must have ever received the attachments which are in “.zip” file extension. In order to access the internal files in one zip file, you have to firstly unzip it. In this case, as usual, you have to first save the zip file to local drive and then right click it and select “Extract All” from the context menu. In reality, many users prefer to unzip the file directly within Outlook. However, Outlook does not provide such a native feature. Fortunately, you can follow the steps thereinafter to utilize VBA to realize it like a breeze.
Unzip the .Zip Attachments Directly in Outlook
- In the first place, launch your Outlook application.
- Then press “Alt + F11” key shortcut in Outlook window to access VBA editor.
- Next in the “Microsoft Visual Basic for Applications” window, open a module that is not in use.
- Subsequently, copy and paste the following VBA codes into this module.
Public Sub UnzipFileInOutlook() Dim objMail As Outlook.MailItem Dim objAttachments As Outlook.attachments Dim objAttachment As Outlook.Attachment Dim objShell As Object Dim objFileSystem As Object Dim strTempFolder As String Dim strFilePath As String Dim strFileName As String Set objMail = Outlook.Application.ActiveInspector.CurrentItem Set objAttachments = objMail.attachments 'Save & Unzip the zip file in local drive Set objShell = CreateObject("Shell.Application") Set objFileSystem = CreateObject("Scripting.FileSystemObject") strTempFolder = objFileSystem.GetSpecialFolder(2).Path & "\Temp" & Format(Now, "yyyy-mm-dd-hh-mm-ss") MkDir (strTempFolder) For Each objAttachment In objAttachments If Right(objAttachment.FileName, 3) = "zip" Then strFilePath = strTempFolder & "\" & objAttachment.FileName objAttachment.SaveAsFile (strFilePath) objShell.NameSpace((strTempFolder)).CopyHere objShell.NameSpace((strFilePath)).Items End If Next 'Reattach the files extracted from the zip file strFileName = Dir(strTempFolder & "\") While Len(strFileName) > 0 objMail.attachments.Add (strTempFolder & "\" & strFileName) strFileName = Dir objMail.Save Wend 'Delete the attachments in “.zip” file extension Set objAttachments = objMail.attachments For Each objAttachment In objAttachments If Right(objAttachment.FileName, 3) = "zip" Then objAttachment.Delete objMail.Save End If Next 'Delete the temp folder and files objFileSystem.DeleteFolder (strTempFolder) End Sub
- After that, you can add the new VBA project to the Quick Access Toolbar of message window as usual.
- Finally, you can have a try.
- First, open a message with zip file in its own window.
- Then click “Actions” > “Edit Message”.
- Next click the new macro button in Quick Access Toolbar.
- At once, the zip file will unzipped, like the following screenshot:
Get Rid of Annoying PST Issues
Though the PST file in new Unicode format supports 20 GB file size, it’s still wise to keep file as small as possible. It is because that a large PST file is much more prone to corruption. Once your PST file gets compromised, you will have to make efforts to recover PST data. In that scenario, you have no choice but to recur to a well-proven and reputable tool like 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 repair and outlook repair software products. For more information visit www.datanumen.com
Leave a Reply