I found this code on another website. It should take an email found in an Outlook folder and unzip the attachment. It uses a temporary location to do this.
I am using Outlook 2013 and the references I am using are: Visual Basic for Application, Microsoft Outlook 15.0 Object Library, OLE Automation, Microsoft Office 15.0 Object Library. I am running this code currently in a module.
Option Explicit
Sub Unzip1()
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Atchmt As Attachment
Dim FileName As String
Dim msg As Outlook.MailItem
Dim ns As Outlook.NameSpace '
Dim FSO As Object 'variables for unzipping
Dim oApp As Object
Dim FileNameFolder As Variant
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders("ASE")
For Each msg In SubFolder.Items
For Each Atchmt In msg.Attachments
If (Right(Atchmt.FileName, 3) = "zip") Then
FileNameFolder = Environ("USERPROFILE") & "Documents\"
Set oApp = CreateObject("Shell.Application")
oApp.NameSpace(FileNameFolder).CopyHere oApp.NameSpace(Atchmt.FileName).Items
End If
Next
Next
End Sub
I am getting an error "Object variable or With block variable not set" on this line.
oApp.NameSpace(FileNameFolder).CopyHere oApp.NameSpace(Atchmt.FileName).Items
Atchmt.SaveAsFile FileNameFolder
afterFileNameFolder = Environ("USERPROFILE") & "Documents\"
– 0m3r