I have an email account that contains two aliases, pod@ and invoices@. There is a rule to move mail received by pod@ to POD folder (Outlook folder, not HDD).
I have run a script VBA code like: Save attachments to a folder and rename them
I need to set the same rule for invoices@ so the attachments are saved to another Network Drive.
If add another script of the same but with different location, I can't choose any of the scripts when setting up the Outlook rule, they become invisible.
I would like to have scripts running in different rules saving attachments to different network folders.
OR
One rule with script that will determine which alias mail was sent to, move mail to specific Outlook folder then save attachments to different network folders.
Also I found a problem running the current script. When trying to save attachments, to the network folder and the network folder is not accessible, the rule crashes.
I don't know VBA or any other languages.
EDITED:
As per answer below:
Public Sub saveAttachtoDisk_invoices (itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String Dim dateFormat
dateFormat = Format(Now, "yyyy-mm-dd H-mm") saveFolder = "C:\Temp\"
on error goto ErrorHandler
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & dateFormat & objAtt.DisplayName
Next
on error goto 0
exit sub
ErrorHandler:
debug.print itm.subject
debug.print err.number & ": " & err.description & " on save line in saveAttachtoDisk_invoices"
resume next
End Sub
I added a message so the end user will know if an error occurs and a file was not save. I have added this line to the ErrorHandler
MsgBox objAtt.DisplayName & ": " & Err.Description
that will display the File name and a description that the path does not exist.