使用VBA在Excel中打开嵌入式对象 [英] Open an Embedded Object in Excel using VBA
问题描述
打开文档后,当我点击PDF对象图标时,它会打开嵌入其中的PDF文件。
使用VBA /宏我想做同样的事情,我必须运行一个宏,它将打开嵌入的PDF文件(不需要点击PDF图标)。
可以吗?
谢谢,
Excel:
您可以从$ $中获取 OLEObject
c $ c> OLEObjects 的工作表
。请参阅 OLEObjects
- https ://msdn.microsoft.com/en-us/library/office/ff840244.aspx , OLEObject
- https://msdn.microsoft.com/en-us/library/office/ff838421.aspx , OLEObject
成员 - https: //msdn.microsoft.com/EN-US/library/office/ff841208.aspx 。
有一种方法动词
其中有一个用于打开对象的动词。请参阅 https://msdn.microsoft.com/EN-US/library/ office / ff838827.aspx - 动词
s - https://msdn.microsoft.com/EN-US/library/office/ff820926.aspx
示例:
Sub test()
With ActiveSheet
Set o = .OLEObjects(Objekt 1)
o.Verb xlVerbOpen
End with
End Sub
Objekt 1是Excel工作表中对象的名称。对象必须在活动表单中。
Word:
这取决于嵌入对象是否在 InlineShape
或 Shape
中。而且没有 OLEObjects
集合。所以你必须用 Shape.OLEFormat
来处理。请参阅 InlineShapes
- https ://msdn.microsoft.com/en-us/library/office/ff822592.aspx ,形状
- https://msdn.microsoft.com/en-us/library/office/ff845240.aspx , Shape
- https:/ /msdn.microsoft.com/en-us/library/office/ff196943.aspx , OLEFormat
- https://msdn.microsoft.com/EN-US/library/office/ff197153.aspx 。
示例:
子测试()
使用ActiveDocument
设置oShape = .InlineShapes(1)'嵌入对象是第一个InlineShape。
'Set oShape = .Shapes(1)'嵌入对象是第一个Shape。
设置oOLEFormat = oShape.OLEFormat
oOLEFormat.Open
结束
End Sub
In an ms office document I've embedded / inserted an external document (object) (PDF in my case).
After opening the document, when I click on the PDF object icon, It opens up the PDF file embedded in it.
Using VBA / Macro I want to do the same thing, Where I'll have to run a macro and it will open up the embedded PDF file(Without clicking on the PDF ICON).
Is it possible?
Thanks,
Excel:
You can get the OLEObject
form the OLEObjects
of the Worksheet
. See OLEObjects
- https://msdn.microsoft.com/en-us/library/office/ff840244.aspx, OLEObject
- https://msdn.microsoft.com/en-us/library/office/ff838421.aspx, OLEObject
members - https://msdn.microsoft.com/EN-US/library/office/ff841208.aspx.
There is a method Verb
which has a verb for opening the object. See https://msdn.microsoft.com/EN-US/library/office/ff838827.aspx - Verb
s - https://msdn.microsoft.com/EN-US/library/office/ff820926.aspx
Example:
Sub test()
With ActiveSheet
Set o = .OLEObjects("Objekt 1")
o.Verb xlVerbOpen
End With
End Sub
"Objekt 1" is the name of the object in the Excel worksheet. The object must be in the active sheet.
Word:
In Word it depends on if the embedded object is in an InlineShape
or an Shape
. And there is no OLEObjects
collection. So you must handle with Shape.OLEFormat
. See InlineShapes
- https://msdn.microsoft.com/en-us/library/office/ff822592.aspx, Shapes
- https://msdn.microsoft.com/en-us/library/office/ff845240.aspx, Shape
- https://msdn.microsoft.com/en-us/library/office/ff196943.aspx, OLEFormat
- https://msdn.microsoft.com/EN-US/library/office/ff197153.aspx.
Example:
Sub test()
With ActiveDocument
Set oShape = .InlineShapes(1) 'The embedded object is the first InlineShape.
'Set oShape = .Shapes(1) 'The embedded object is the first Shape.
Set oOLEFormat = oShape.OLEFormat
oOLEFormat.Open
End With
End Sub
这篇关于使用VBA在Excel中打开嵌入式对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!