I have a piece of VBA script that saves attachments, and is activated using outlook Rules.
The attachment I'm interested in comes once a day and always has the same name, so I want to concatenate the subject of the email - which does change each day (or concatenate the date of the email).
I have never done VBA before and the following *works* as long as 'emailsubject' is set equal to a "string like this":
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim emailsubject As String
emailsubject = "string like this"
saveFolder = "D:\Users\AAA\Reporting\"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & emailsubject & objAtt.DisplayName
Set objAtt = Nothing
I have tried setting emailsubject equal to each of the following :
emailsubject = Outlook.olMailItem.Subject
emailsubject = Item.Subject
emailsubject = olMailItem.Subject
emailsubject = MailItem.Subject
emailsubject = objMsg.Subject
But none of these work - what is wrong / missing?