Saving Attachments

  • Thread starter Thread starter Edgar Thoemmes
  • Start date Start date
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
 
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
 
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
 
Back
Top