Auto Save attachments

  • Thread starter Thread starter Ed
  • Start date Start date
E

Ed

Hi

I have the following code which checks a new email message
for attachments and if it finds any saves them to a
specific folder on my hard drive. I need it instead of
saving the file name as the original attachment name to
save as the subject of the email instead. I think i know
how do this but i dont know how to refer to the subject of
the message in code. Does any have any ideas?

Private Sub objInbox_ItemAdd(ByVal Item As Object)
If Item.Class = olMail And Item.Subject = "Test Att"
Then
If Item.Attachments.Count > 0 Then
Dim objAttachments As Outlook.Attachments
Set objAttachments = Item.Attachments
For Each objAttach In objAttachments
' Does not handle duplicate filename scenarios
objAttach.SaveAsFile "C:\remit\" &
objAttach.FileName
Next
Set objAttachments = Nothing
End If
End If
End Sub
 
Item.Subject would give you the subject of the message. When in doubt, check
the object browser: Press ALt+F11 to open the VBA environment in Outlook,
then press F2.

Think carefully, though, about what you want to have happen if the message
has more than one attachment.
 
Back
Top