I have VBA code to look for attachments in e-mails in a specific Outlook folder and save them into a location.
I have an Outlook rule that sends the emails to the Outlook folder then fires the macro. The code does not fire on my computer automatically, but it does on another computer. The email comes in and the rule drops it into the folder, but the code does not run. When I run the code manually, through the VB Editor, it saves the attachment in the right place.
I have checked to make sure folder and path names are correct (either way if they were wrong the code would not run properly when I run it manually).
Outlook rule:
Apply this rule after the message arrives
from xxxxxxxxxxxx
and with xxxx in the subject
and on this machine only
move it to the xxxxx folder
and run Project1.ThisOutlookSession.Save
VBA code:
Sub Save(item As Outlook.MailItem)
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim msg As Outlook.MailItem
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
Set olFolder = olFolder.Folders("xxxxxxx")
Set oApp = CreateObject("Shell.Application")
For Each myitem In olFolder.Items
For Each att In myitem.Attachments
att.SaveAsFile "\\.............\" & att.FileName
myitem.Attachments.Remove 1
myitem.Save
Next
Next
End Sub