从 Powerpoint 添加对 Excel 对象库的引用
Add reference to Excel object library from Powerpoint
我正在尝试以编程方式从 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 中做类似的事情吗?
这是代码
Sub Add_References_Programmatically()
Dim VBAEditor As Object
Dim vbProj As Object
Dim chkRef As Object
Set VBAEditor = Application.VBE
Set vbProj = ActivePresentation.VBProject
On Error Resume Next
vbProj.References.AddFromGuid "{0002E157-0000-0000-C000-000000000046}", 5, 0
On Error GoTo 0
For Each chkRef In vbProj.References
If chkRef.Name = "Excel" Then
MsgBox "The Reference Is Already Added", 64
GoTo CleanUp
End If
Next chkRef
vbProj.References.AddFromFile "C:\Program Files\Microsoft Office\Root\Office16\EXCEL.EXE"
CleanUp:
Set vbProj = Nothing
Set VBAEditor = Nothing
End Sub
我正在尝试以编程方式从 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 中做类似的事情吗?
这是代码
Sub Add_References_Programmatically()
Dim VBAEditor As Object
Dim vbProj As Object
Dim chkRef As Object
Set VBAEditor = Application.VBE
Set vbProj = ActivePresentation.VBProject
On Error Resume Next
vbProj.References.AddFromGuid "{0002E157-0000-0000-C000-000000000046}", 5, 0
On Error GoTo 0
For Each chkRef In vbProj.References
If chkRef.Name = "Excel" Then
MsgBox "The Reference Is Already Added", 64
GoTo CleanUp
End If
Next chkRef
vbProj.References.AddFromFile "C:\Program Files\Microsoft Office\Root\Office16\EXCEL.EXE"
CleanUp:
Set vbProj = Nothing
Set VBAEditor = Nothing
End Sub