查找对象库VBA的VBIDE.Reference.Name [英] Finding the VBIDE.Reference.Name of object libraries vba
问题描述
我找到了如何使用VBA编程添加参考,
这说明了如何使用库的名称以编程方式添加对象引用,
并带有示例 VBScript_RefExp_55。
I've found how to add a reference programmatically with VBA,
This explains how to add object references programmatically using the name of the Library,
with the example "VBScript_RefExp_55".
我的问题是如何找到在此代码中用于不同对象库的引用名称?
例如PowerPoint库?
My question is how do I find this reference name to use in this code for different object libraries?
Such as the PowerPoint Library for example?
推荐答案
我用它来获取我的参考文献信息:
I use this to get the info on my references :
Private Sub ListProjectReferencesList()
Dim i As Long
Dim VBProj As Object 'VBIDE.VBProject
Dim VBComp As Object 'VBIDE.VBComponent
Set VBProj = Application.VBE.ActiveVBProject
Dim strTmp As String
On Error Resume Next
For i = 1 To VBProj.References.Count
With VBProj.References.Item(i)
Debug.Print "Description: " & .Description & vbNewLine & _
"FullPath: " & .FullPath & vbNewLine & _
"Major.Minor: " & .Major & "." & .Minor & vbNewLine & _
"Name: " & .Name & vbNewLine & _
"GUID: " & .GUID & vbNewLine & _
"Type: " & .Type
Debug.Print "-------------------"
End With 'VBProj.References.Item(i)
Next i
End Sub
通常,我更喜欢使用GUID而不是名称来添加它。
And generally, I prefer to add it with GUID rather than name.
但是正如@Rory指出的那样,
您应该使用Late Binding而不是比通过编程方式添加引用!
But as pointed out by @Rory,
you should use Late Binding rather than adding References programmatically!
为什么?
>因为,要以编程方式添加它们,您的用户将必须进入:
Because in order to add them programmatically, your users will have to go into :
- 选项
- 信任中心
- 信任中心设置
- 宏设置选项卡
- 打勾信任对VBA项目对象模型的访问权限复选框
- 确定 >
- 确定
- Options of the Application (Excel, ...) from which it's launched
- Trust Center
- Trust Center Settings
- Macro Settings tab
- Tick Trust access to the VBA project object model check box
- OK
- OK
因此,最好使用引用来完成代码,然后:
- 删除引用
- 使用这些库将所有声明更改为
Dim ???作为对象
- 检查是否具有
显式选项
在模块顶部(如果没有添加,则添加它) - 查找应用专用变量((
Option Explicit
应该向他们发送消息) - 测试很多代码
- 导出模块以供他人使用!
- Remove the references
- Change all declarations using those librairies to
Dim ??? As Object
- Check if you have
Option Explicit
at the top of the module (add it if not) - Look for app-specific variables (
Option Explicit
should throw an message on them) - Test your code a lot
- Export module to be used by others!
这篇关于查找对象库VBA的VBIDE.Reference.Name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!