Extract OLE object data in Microsoft Office without OLE application

倖福魔咒の 提交于 2019-12-11 04:02:05

问题


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


来源:https://stackoverflow.com/questions/8590595/extract-ole-object-data-in-microsoft-office-without-ole-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!