"Word Cannot Obtain The Data..." Error Message When Programmatically Embedding an OLE Object (819031)



The information in this article applies to:

  • Microsoft Word 2002

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:="Package", _
   FileName:="http://servername/filename.xls ", _
   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: For additional information about the support options available from Microsoft, visit the following Microsoft Web site:

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:="Package", _
   FileName:="http://servername/filename.xls ", _
   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("ADODB.Record")
   Set oStm = CreateObject("ADODB.Stream")

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

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

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

End Sub

STATUS

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

Modification Type:MajorLast Reviewed:5/15/2003
Keywords:kberrmsg kbprb KB819031 kbAudEndUser