vba 无需 OLE 应用程序即可在 Microsoft Office 中提取 OLE 对象数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8590595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 14:45:27  来源:igfitidea点击:

Extract OLE object data in Microsoft Office without OLE application

vbams-officevstoole

提问by Paul B.

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.

是否可以使用 VBA/VSTO 在 Microsoft Office 中提取嵌入的 OLE 对象的内容?我说的是创建 OLE 对象的应用程序不可用的情况。在这种情况下,某种转换器应用程序可以使用原始数据。

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

例如,在 Excel 中,可以通过访问对象,ActiveSheet.Shapes(x).OLEFormat但我还没有找到检索对象原始数据的方法。

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?

一种方法是打开本机文件(Office Open XML/复合文件)并从中提取数据。但也许有更简单的方法?

回答by Jon49

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

将 复制OLEObject到剪贴板,然后从剪贴板中获取它,例如 VSTO 中的类似内容:

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

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

在 VBA 中,我刚刚打开一个文件夹,Shell然后使用SendKeys.

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

回答by onit

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

复制OLEObject到剪贴板,然后将其从剪贴板复制到文件夹中的“ Shell.Application”(动词Paste

 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