【发布时间】:2018-03-01 10:39:40
【问题描述】:
我正在尝试以编程方式从 Powerpoint 宏中引用 Excel 16.0 对象库。我似乎找不到任何有关如何执行此操作的信息。
我认为这是在 Excel 工作簿中添加库引用的代码:
Sub AddReference()
Dim VBAEditor As VBIDE.VBE
Dim vbProj As VBIDE.VBProject
Dim chkRef As VBIDE.Reference
Dim BoolExists As Boolean
Set VBAEditor = Application.VBE
Set vbProj = ActiveWorkbook.VBProject
'~~> Check if reference is already added
For Each chkRef In vbProj.References
If chkRef.Name = "Microsoft Excel 16.0 Object Library" Then
BoolExists = True
GoTo CleanUp
End If
Next
vbProj.References.AddFromFile "C:\Program Files\Microsoft Office\Root\Office 16\EXCEL.EXE"
CleanUp:
Set vbProj = Nothing
Set VBAEditor = Nothing
End Sub
Adapted from here - Siddharth Rout
但是,我得到了一个未在 Powerpoint 中定义的用户定义类型。我认为这是因为 Sub 开头的对象不同。有人知道如何在 Powerpoint 中做类似的事情吗?
【问题讨论】:
-
在 VBE >> 从工具菜单 >> 参考 >> 检查选项“Microsoft Visual Basic for Application Extensibility 5.3” .. 您必须将 ActiveWorkbook 更改为 ActivePresentation,因为您将使用 Powerpoint 中的代码您应该检查宏设置>>信任对 VBA 项目模型的访问
标签: vba excel reference powerpoint