Microsoft KB Archive/198897

= DOC: Incorrect Attachment Name/Icon For Word/Excel Attachments =

Article ID: 198897

Article Last Modified on 3/4/2004

-

APPLIES TO


 * Microsoft Collaboration Data Objects 1.2
 * Microsoft Collaboration Data Objects 1.21

-



This article was previously published under Q198897



SUMMARY
In the "Adding Attachments to a Message" topic under "Programming Tasks" in the CDO (1.2x) 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

Keywords: kbmsg kbdocfix kbprb kbdocerr KB198897

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.