Im really new to VBA and need some help. I'm trying to write a VBA script (along with a Outlook rule) to automatically download attachments from daily emails that contain multiple attachements and append the file names with the date that always appears at the end of the subject line.
This is what the subject line looks like - "Email Alert for Department for 10/20/2014". I just need to isolate the rightmost 10 spaces that indicates the run date of the files.
So I found code online that works to automatically download the attachments and append by current date which does work. See below.
I tried to modify the code to append the file name by using the last 10 spaces of the subject line instead of the current date but when I ran the rule with the script it did not work.
I feel like its something small I'm overlooking. Any thoughts?
This is what the subject line looks like - "Email Alert for Department for 10/20/2014". I just need to isolate the rightmost 10 spaces that indicates the run date of the files.
So I found code online that works to automatically download the attachments and append by current date which does work. See below.
Code:
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim dateFormat
dateFormat = Format(Now, "yyyymmdd ")
saveFolder = "Z:\Daily Emails"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & dateFormat & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub
I tried to modify the code to append the file name by using the last 10 spaces of the subject line instead of the current date but when I ran the rule with the script it did not work.
Code:
Public Sub saveAttachtoDiskCL(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim savefolder As String
Dim Subject As String
savefolder = "Z:\Daily Emails"
For Each objAtt In itm.Attachments
Subject = itm.Subject
'Isolate last 10 spaces
Subject = Right(itm.Subject, 10)
objAtt.SaveAsFile savefolder & "\" & objAtt.DisplayName & Subject
Set objAtt = Nothing
Next
End Sub
I feel like its something small I'm overlooking. Any thoughts?