Article ID: 196080
Article Last Modified on 3/4/2004
' The code below assumes a reference to the CDO (1.1, 1.2, 1.21)
' Library. However if you are using CDO (1.1), then you must
' change the name of the Cdo_PR_ATTACH_NAME constant to instead
' be ActMsgPR_ATTACH_NAME
'
Option Explicit
Dim objSession As MAPI.Session
Dim myMsg As MAPI.Message
Dim newMsg As MAPI.Message
Dim myAttach As MAPI.Attachment
Dim newAttach As MAPI.Attachment
Private Sub Command1_Click()
Set objSession = CreateObject("MAPI.Session")
objSession.Logon
MsgBox "CDO version = " & objSession.Version
Set myMsg = objSession.Inbox.Messages.GetFirst
'MsgBox "myMsg.Subject is: " & myMsg.Subject
Set myAttach = myMsg.Attachments.Item(1)
'MsgBox "Attach Name is : " & myAttach.Name
'MsgBox "Attach Type is : " & myAttach.Type
'MsgBox "Attach Class is : " & myAttach.Class
'MsgBox "Attach Method is : " & myAttach.Fields(CdoPR_ATTACH_METHOD)
myAttach.WriteToFile "C:\temp\attach.bmp"
Set newMsg = objSession.Outbox.Messages.Add
newMsg.Subject = "Re: " & myMsg.Subject
newMsg.Text = "Re: " & myMsg.Text
Set newAttach = newMsg.Attachments.Add
newAttach.Name = "attach.bmp"
newAttach.Type = myAttach.Type
newAttach.Position = myAttach.Position
newAttach.ReadFromFile "C:\temp\attach.bmp"
newMsg.Update
objSession.Logoff
End Sub
newAttach.ReadFromFile "C:\temp\attach.bmp"
newAttach.Type = myAttach.Type
to
newAttach.Type = CdoFileData 'For CDO (1.2 or 1.21)
or:
newattach.Type = ActMsgFileData 'For CDO (1.1)
Keywords: kbmsg kbprb KB196080