F
Frank
Hi,
I'm trying to implement a solution that saves all my attachments in a folder
automatically.
I found the code below that is a good start.
However, I have some questions:
1.) How can I make a simple method like the one below visible in the outlook
menu or toolbar?
2.) I would like to run a "rule" and execute a script when I receive an
email with attachment. I know how to setup the rule. But I don't know how to
structure the script to receive the proper input value and execute SaveAs
only for this email
Any help would be appreciated.
Private Sub SaveAttachements()
Const olFolderInbox = 6
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
Set colItems = objFolder.Items
Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
For Each objMessage In colItems
intCount = objMessage.Attachments.Count
If intCount > 0 Then
For i = 1 To intCount
strTempFile = objFSO.GetTempName
objMessage.Attachments.Item(i).SaveAsFile
"C:\mailarchive\attachments\" & strTempFile & "_" & _
objMessage.Attachments.Item(i).FileName
Next
End If
Next
End Sub
I'm trying to implement a solution that saves all my attachments in a folder
automatically.
I found the code below that is a good start.
However, I have some questions:
1.) How can I make a simple method like the one below visible in the outlook
menu or toolbar?
2.) I would like to run a "rule" and execute a script when I receive an
email with attachment. I know how to setup the rule. But I don't know how to
structure the script to receive the proper input value and execute SaveAs
only for this email
Any help would be appreciated.
Private Sub SaveAttachements()
Const olFolderInbox = 6
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
Set colItems = objFolder.Items
Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
For Each objMessage In colItems
intCount = objMessage.Attachments.Count
If intCount > 0 Then
For i = 1 To intCount
strTempFile = objFSO.GetTempName
objMessage.Attachments.Item(i).SaveAsFile
"C:\mailarchive\attachments\" & strTempFile & "_" & _
objMessage.Attachments.Item(i).FileName
Next
End If
Next
End Sub