Auto Save attachments

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
 
S

Sue Mosher [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top