Paul B.
Paul B.

Reputation: 2524

Extract OLE object data in Microsoft Office without OLE application

Is it possible to extract the content of an embedded OLE object in Microsoft Office using VBA/VSTO? I am talking about a situation where the application with which the OLE object was created is not available. In this case some sort of converter application could make use of the raw data.

For instance, in Excel the object is accessible via ActiveSheet.Shapes(x).OLEFormat but I have not found a way to retrieve the raw data of the object.

One way would be to open the native file (Office Open XML/Compound File) and extract the data from there. But maybe there is a simpler approach?

Upvotes: 2

Views: 9243

Answers (3)

KERR
KERR

Reputation: 1702

I approached this another way (non-VBA).

  • Rename the document/spreadsheet to .zip (eg instead of .docx)
  • Open the .zip and browse the structure to the embedded objects eg \word\embeddings enter image description here
  • Edit the .bin file(s) (eg in Notepad++) - you should be able to identify the file extension in the first 10 lines enter image description here
  • Now strip all the header/junk from the start of the file - search for ÐÏࡱ and remove everything before/above it

enter image description here

  • The beginning of the file will now look like this:

enter image description here

  • Save the file with the extension that you identified above
  • The file should open and function correctly

Upvotes: 0

onit
onit

Reputation: 11

Copy the OLEObject to the clipboard, then get it over "Shell.Application" (verb Paste) from the clipboard to folder

 For Each Sh In Sheet1.OLEObjects
  If InStr(1, Sh.Name, "Object", 1) Then
   Sh.Copy 
   ' this code paste Embedded Object to folder
   CreateObject("Shell.Application").Namespace("c:\temp\!").Self.InvokeVerb "Paste"
  End If
 Next Sh

Upvotes: 1

Jon49
Jon49

Reputation: 4606

Copy the OLEObject to the clipboard then get it from the clipboard, e.g. something like this in VSTO:

Dim ole as OLEObject
...
ole.Copy
...
Clipboard.GetData("Embedded Object")

In VBA I have just been opening a folder through Shell then pasting using SendKeys.

ole.copy
Shell "explorer.exe " & sFolderName, vbNormalFocus
Application.Wait Now() + TimeSerial(0, 0, 3)
Application.Sendkeys "^v"

Upvotes: 3

Related Questions