Reputation: 189
I'm using the following code to save email photo's to a specific folder :
Private Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "C:\Temp\"
For Each objAtt In itm.Attachments
If objAtt.FileName <> "image001.gif" Then
objAtt.SaveAsFile saveFolder & "\" & itm.Subject & ".JPG"
End If
Set objAtt = Nothing
Next
End Sub
However I can't get it to actually work. I've tried saving it in ThisOutlookSession and as a module attached to a rule but nothing is being saved.
I'm also looking to create another script to save the comments of the email to a text file where the specific text would be written in [COMMENT] tags in the body. Is this possible ?
Upvotes: 1
Views: 7045
Reputation: 189
This is the code I got to work :
Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim dateFormat
dateFormat = Format(Now, "yyyy-mm-dd")
'Message subject should be the meter serial number i.e.K11TB00864
Dim subject
subject = Trim(itm.subject)
Dim saveFolder As String
saveFolder = "C:\Temp\Photo"
For Each objAtt In itm.Attachments
If objAtt.FileName <> "image001.gif" Then
objAtt.SaveAsFile saveFolder & "\" & itm.subject & " " & dateFormat & ".jpg"
End If
Set objAtt = Nothing
Next
End Sub
Upvotes: 1
Reputation: 9179
There is an extra "\" in the path.
Try objAtt.SaveAsFile saveFolder & itm.Subject & ".JPG"
or saveFolder = "C:\Temp"
Upvotes: 2