DOC: Incorrect Attachment Name/Icon For Word/Excel AttachmentsID: Q198897
|
In the "Adding Attachments to a Message" topic under "Programming Tasks" in the CDO help file, it is stated that for CdoFileData and CdoOle type of attachments, ReadFromFile method and for CdoFileLink type of attachments, Source method of the Attachment object needs to be used. The documentation also includes two code samples demonstrating how to use each method.
When you specify the attachment type as CdoOle and use the first code sample (as suggested) to add a Microsoft Excel file or a Microsoft Word file attachment, you will see that the code fails to put the correct display name and program icon for the attachment.
For example, if you add a Microsoft Excel file attachment to a message, the attachment might appear with a non-Excel icon and a display name "Microsoft Excel Work...".
To add a Microsoft Excel file (or a Microsoft Word file) attachment to a message, use the following code sample instead of the code samples in the document:
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
Additional query words: kbDSupport kbdocfix kbdocerr kbCDO120 kbCDO121 kbCDO kbMsg
Keywords : kbdocfix kbCDO kbCDO120 kbCDO121 kbMsg kbDSupport
Version : WINDOWS:1.2,1.21
Platform : WINDOWS
Issue type :
Last Reviewed: July 27, 1999