Microsoft KB Archive/819031

= &quot;Word Cannot Obtain The Data...&quot; Error Message When Programmatically Embedding an OLE Object =

Article ID: 819031

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Word 2002 Standard Edition

-



SYMPTOMS
When you try to programmatically embed an OLE object in a Word 2002 document and the object is located in a Web folder, you receive the following error message:

Word cannot obtain the data for the http://server/filename link.



CAUSE
This problem occurs if you run the following Visual Basic for Applications sample macro: Sub Test

Selection.InlineShapes.AddOLEObject ClassType:=&quot;Package&quot;, _ FileName:=&quot;http://servername/filename.xls &quot;, _ LinkToFile:=False, DisplayAsIcon:=False

End Sub



WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, see the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For additional information about the support options available from Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

To work around this problem, use one of the following methods:

Method 1: Link the Embedded Object
Change the LinkToFile statement to True as in the following sample Microsoft Visual Basic for Applications macro to link the embedded object in your Word document: Sub Test

Selection.InlineShapes.AddOLEObject ClassType:=&quot;Package&quot;, _ FileName:=&quot;http://servername/filename.xls &quot;, _ LinkToFile:=True, DisplayAsIcon:=False

End Sub

Method 2: Embed a Local Copy of the File
Use the following sample Visual Basic for Applications macro to copy a file from a Web server to the local hard disk, insert the copy of the file as an embedded object in your Word document, and then delete the file copy. Sub InsertObj

Const adModeRead = 1 Const adOpenIfExists = 33554432 Const adOpenStreamFromRecord = 4 Const adTypeBinary = 1 Const adSaveCreateOverWrite = 2

Dim oRec 'ADODB.Record Dim oStm 'ADODB.Stream

Set oRec = CreateObject(&quot;ADODB.Record&quot;) Set oStm = CreateObject(&quot;ADODB.Stream&quot;)

' Open a particular file at the URL... oRec.Open &quot;WB01624_.gif&quot;, &quot;URL=http://test.com/&quot;, adModeRead, adOpenIfExists

' Use an ADO Stream object to read the contents of the file... oStm.Type = adTypeBinary oStm.Open oRec, adModeRead, adOpenStreamFromRecord oStm.SaveToFile &quot;C:\Test\WB01624_.gif&quot;, adSaveCreateOverWrite oStm.Close oRec.Close Set oStm = Nothing Set oRec = Nothing

'Code to the insert object Selection.InlineShapes.AddOLEObject ClassType:=&quot;Package&quot;, FileName:= _ &quot;C:\Test\WB01624_.gif&quot;, LinkToFile:=False, DisplayAsIcon:=False Kill &quot;C:\Test\WB01624_.gif&quot;

End Sub



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

Additional query words: OFFQFE 8317

Keywords: kberrmsg kbprb KB819031

-

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

© Microsoft Corporation. All rights reserved.