Search code examples
vbams-officevstoole

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?


Solution

  • 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"