查找对象库VBA的VBIDE.Reference.Name [英] Finding the VBIDE.Reference.Name of object libraries vba

查看:385
本文介绍了查找对象库VBA的VBIDE.Reference.Name的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了如何使用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 :


  1. 选项

  2. 信任中心

  3. 信任中心设置

  4. 宏设置选项卡

  5. 打勾信任对VBA项目对象模型的访问权限复选框

  6. 确定
  7. >
  8. 确定

  1. Options of the Application (Excel, ...) from which it's launched
  2. Trust Center
  3. Trust Center Settings
  4. Macro Settings tab
  5. Tick Trust access to the VBA project object model check box
  6. OK
  7. OK

因此,最好使用引用来完成代码,然后


  1. 删除引用

  2. 使用这些库将所有声明更改为 Dim ???作为对象

  3. 检查是否具有 显式选项 在模块顶部(如果没有添加,则添加它)

  4. 查找应用专用变量(( Option Explicit 应该向他们发送消息)

  5. 测试很多代码

  6. 导出模块以供他人使用!

  1. Remove the references
  2. Change all declarations using those librairies to Dim ??? As Object
  3. Check if you have Option Explicit at the top of the module (add it if not)
  4. Look for app-specific variables (Option Explicit should throw an message on them)
  5. Test your code a lot
  6. Export module to be used by others!

这篇关于查找对象库VBA的VBIDE.Reference.Name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆