Article ID: 198897
Article Last Modified on 3/4/2004
Function Attachments_Add_Data()
Dim objMessage As Message ' local
Dim objRecip As Recipient ' local
On Error GoTo error_olemsg
If objSession Is Nothing Then
MsgBox ("must first log on; use Session->Logon")
Exit Function
End If
Set objMessage = objSession.Outbox.Messages.Add
If objMessage Is Nothing Then
MsgBox "could not create a new message in the Outbox"
Exit Function
End If
With objMessage ' message object
.Subject = "attachment test"
.Text = "Have a nice day."
.Text = " " & objMessage.Text ' add placeholder for attachment
Set objAttach = .Attachments.Add ' add the attachment
If objAttach Is Nothing Then
MsgBox "Unable to create new Attachment object"
Exit Function
End If
With objAttach
.Type = CdoFileData
.Position = 0 ' render at first character of message
.Name = "MyExcelFile.xls"
.Source "c:\MyExcelFile.xls"
End With
.Update ' update message to save attachment in MAPI system
End With
MsgBox "Created message, added 1 CdoFileData attachment, updated"
Exit Function
error_olemsg:
MsgBox "Error " & Str(Err) & ": " & Error$(Err)
Resume Next
End Function
Keywords: kbmsg kbdocfix kbprb kbdocerr KB198897