有没有办法在运行之前自动让Excel 2010“自动检查”VBA引用中的Powerpoint引用?
答案 0 :(得分:0)
这样的事情应该可以解决问题。让我知道它是否给你带来任何麻烦(我修改了一些现有的功能,我可能会输错字等等。
注意:这适用于Office 2010.
Const PPTReference as String = "C:\Program Files (x86)\Microsoft Office\Office14\POWERPOINT.EXE"
Const PPTDescription as String = "Microsoft PowerPoint 14.0 Object Library"
Private Sub Workbook_Open()
Call AddRefToPowerPointObjectLibrary
End Sub
Private Sub AddRefToPowerPointObjectLibrary()
'Adds a programmatic refernce to Excel, if one does not already exist
If Not RefExists(PPTReference, PPTDescription) Then
Application.VBE.ActiveVBProject.References.AddFromFile PPTReference
Else:
'Already Installed
End If
End Sub
Function RefExists(refPath As String, refDescrip As String) As Boolean
'Returns true/false if a specified reference exists, based on LIKE comparison
' to reference.description.
Dim ref As Variant
Dim bExists As Boolean
'Assume the reference doesn't exist
bExists = False
For Each ref In Application.VBE.ActiveVBProject.References
If ref.Description Like refDescrip Then
PPT_RefExists = True
Exit Function
End If
Next
PPT_RefExists = bExists
End Function
<强>更新强>
在调用依赖于早期绑定到PowerPoint对象模型的任何过程之前,必须运行此代码 。
例如,您无法执行此操作:
Sub DontDoThis()
Dim pptApp as PowerPoint.Application
AddRefToPowerPointObjectLibrary
Set pptApp = New PowerPoint.Application
'more code...
End Sub
将上述代码放在上面修改的Workbook_Open事件处理程序中可能是最可靠的。