PDA

View Full Version : Auto save and unzip attachments



Bassie
08-23-2010, 07:28 AM
Hi,

Everyday I receive several emails with zipped attachments.
I want to save the unzipped attachements to my local disk.
Can anyone help me?

I use the code below to save it, but I don't now how to unzip it

Sub GetAttachments()
On Error GoTo GetAttachments_err
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Subfolder As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim datum As String
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set Subfolder = Inbox.Folders("XXX")
i = 0

If Subfolder.Items.Count = 0 Then
MsgBox "There are no messages in the Sales Reports folder." _
, vbInformation, "Nothing Found"
Exit Sub
End If
If Subfolder.Items.Count > 0 Then
For Each Item In Subfolder.Items
For Each Atmt In Item.Attachments
FileName = "C:\Temp\" & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
Next Atmt
Next Item
End If
If i > 0 Then
MsgBox "I found " & i & " attached files." _
& vbCrLf & "I have saved them into the C:\Email Attachments folder." _
& vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
Else
MsgBox "I didn't find any attached files in your mail.", vbInformation, _
"Finished!"
End If
GetAttachments_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Exit Sub
GetAttachments_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: GetAttachments" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume GetAttachments_exit

End Sub

Imdabaum
08-31-2010, 10:23 AM
Maybe try this I found in Googlegroups

http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_thread/thread/a594bd2f91931f24/8e6f06d859a21886?lnk=st&q=FileSystemObject+UNCOMPRESS&rnum=2&hl=en&pli=1


dim fso, strFile
strFile = "d:\tempp\test.txt"


set fso=createObject("Scripting.fileSystemObject")
set wshShell = createObject("Wscript.Shell")
set fl = fso.getFile(strFile)
if (fl.attributes AND 2048) then
strCompactCmd = "%comspec% /c compact /u """ & strFile &
""""
wscript.echo "Trying to uncompress...using command:" &
strCompactCmd
set objOut = wshShell.exec(strCompactCmd)
while objOut.status=0
wscript.sleep 1000
wend
strOP=objOut.StdOut.ReadAll()
if instr(1,strOP,"[OK]") = 0 then
wscript.echo "Error uncompressing file: " & strFile
'wscript.echo strOP
else
wscript.echo "File: " & strFile & " uncompressed
successfully"
end if
else
wscript.echo "File is not compressed, aborting uncompress
operation."
end if