Not going to win any prizes but ..
Sub UnzipSaveAttachtoDisk(itm As Outlook.mailItem)
Dim objAtt As attachment
Dim sFileName As String
Dim oApp As Object
Dim FileNameFolder As Variant
Dim saveFolder As String
saveFolder = "H:\UnzipFolder"
If itm.Attachments.count > 0 Then
For Each objAtt In itm.Attachments
If Right(objAtt.FileName, 3) = "zip" Then
FileNameFolder = "H:\Temp"
sFileName = FileNameFolder & "\" & objAtt.FileName
objAtt.SaveAsFile sFileName
Set oApp = CreateObject("Shell.Application")
oApp.Namespace((FileNameFolder)).CopyHere oApp.Namespace((sFileName)).Items
Kill sFileName
Rename_Files
Else
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
End If
Next objAtt
End If
Set itm = Nothing
Set oApp = Nothing
End Sub
Sub Rename_Files()
Dim Path_FileNm_w_ext As String
Dim FileNm_w_Ext As String
Dim FileNm As String
Dim ext As String
Dim origPath As String
Dim saveFolder As String
Dim newName As String
origPath = "H:\Temp"
saveFolder = "H:\UnzipFolder"
FileNm_w_Ext = Dir(origPath & "\" & "*.*")
Do While FileNm_w_Ext <> ""
ext = Right$(FileNm_w_Ext, Len(FileNm_w_Ext) - InStrRev(FileNm_w_Ext, ".") + 1)
Path_FileNm_w_ext = origPath & "\" & FileNm_w_Ext
FileNm = FileNameNoExt(Path_FileNm_w_ext)
newName = InputBox("Do not key the extension " & ext & vbCr & " Enter new name for " & FileNm, , FileNm)
newName = Trim(newName)
Debug.Print " saveFolder & newName & ext: " & saveFolder & newName & ext
Name origPath & "\" & FileNm_w_Ext As saveFolder & "\" & newName & ext
FileNm_w_Ext = Dir
Loop
End Sub
Function FileNameNoExt(strPath As String) As String
Dim strTemp As String
strTemp = Mid$(strPath, InStrRev(strPath, "\") + 1)
FileNameNoExt = Left$(strTemp, InStrRev(strTemp, ".") - 1)
End Function
Private Sub UnzipSaveAttachtoDisk_test()
Dim currItem As mailItem
Set currItem = Application.ActiveInspector.currentItem
Debug.Print "currItem.Subject: " & currItem.Subject
UnzipSaveAttachtoDisk currItem
End Sub
Change the temp folder savefolder in both places.
Test with UnzipSaveAttachtoDisk_test. Unzips and saves if necessary, just saves if not a zipped file.
Run through the code with F8 in the editor. You should know what is happening, especially when the code includes a "Kill".