Extract OLE object data in Microsoft Office withou

2019-07-18 06:15发布

问题:

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?

回答1:

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"


回答2:

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