I'm trying to get a VBA macro in Outlook that will save an email's attachment to a specific folder and add the date received to the file name.
My googling has gotten me this far:
Public Sub saveAttachtoDisk (itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim dateFormat As String
saveFolder = "C:\Temp\"
dateFormat = Format(Now, "yyyy-mm-dd H-mm")
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & dateFormat & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub
The first obvious thing is that it's applying the current time to the file name instead of the received time, but I can't seem to change it. My theory is that the Outlook.Attachment doesn't have a ReceivedTime
and that the email itself has to be referenced.
Secondly, this doesn't seem to work at all, ha! It worked the first day I started tinkering but after that it stopped saving files.