Saving Attachments

E

Edgar Thoemmes

Hi

I have the following code that checks incoming messages
and if they meet certain conditions it should copy them to
a specific folder on my hard drive. When I receive a new
message from the person i have specified in the Sender
Name property I get a message box saying that 'A program
is trying to access an outlook item' so it looks like most
of the code is working but when i go to the folder that i
have specified it hasnt copied it there. Any help would be
much appreciated.

Private Sub objInbox_ItemAdd(ByVal Item As Object)

If Item.Class = olMail And Item.Subject = "Test Att"
Then
If Item.SenderName = "Edgar Thoemmes" 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\" &
Item.Subject & ".rtf"
Next
Set objAttachments = Nothing
End If
End If
End If

End Sub
 
E

Edgar Thoemmes

Hi

i have to use the subject of the message as the file name
as these are sent from Crystal Reports which generates one
file name for a report and we split it up by emailing them.

The subject will never contain any invalid characters. I
am not to bothered about the pop up box at the moment as
our back office staff are looking at it.

The problem is the attachments are still not saving. Any
help would be much appreciated.

Thanks
 
D

Dmitry Streblechenko \(MVP\)

Are you sure sure? Replying to an e-mail will put a "RE: " prefix to the
subject, that won't be valid for a filename. Why not use the
Attachment.Filename property, or at the very list loop through all subject
chars replacing all invalid chars with, say, "_"?
Check the attachment type - Attchment.Type must be olByValue for SaveAsFile
to work properly.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

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