如何用vba遍历当前vba工程中添加的引用?

如下图所示

2

为vba工程中添加的引用,由于这个引用对话框无法最大化,看不到具体的每个引用的完整路径。

这时候可以用VBProject对象的References属性返回所有已添加的引用。

代码如下:

Sub QQ1722187970()
    Dim oWK As Worksheet
    Set oWK = ActiveSheet
    oWK.Cells.Clear
    arr = VBA.Array("引用的名称", "引用的路径", "GUID", "Major", "Minor", "说明")
    iCol = UBound(arr) + 1
    oWK.Range("a1").Resize(1, iCol) = arr
    Dim oRef As Reference
    With oWK
        i = 2
        '遍历所有的引用
        For Each oRef In ThisWorkbook.VBProject.References
            With oRef
                oWK.Cells(i, 1) = .Name
                oWK.Cells(i, 2) = .FullPath
                oWK.Cells(i, 3) = .GUID
                oWK.Cells(i, 4) = .Major
                oWK.Cells(i, 5) = .Minor
                oWK.Cells(i, 6) = .Description
                i = i + 1
            End With
        Next
    End With
End Sub

结果如下表所示:

引用的名称 引用的路径 GUID Major Minor 说明
VBA C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA7.1\VBE7.DLL {000204EF-0000-0000-C000-000000000046} 4 2 Visual Basic For Applications
Excel C:\Program Files (x86)\Microsoft Office\Root\Office16\EXCEL.EXE {00020813-0000-0000-C000-000000000046} 1 9 Microsoft Excel 16.0 Object Library
stdole C:\Windows\SysWOW64\stdole2.tlb {00020430-0000-0000-C000-000000000046} 2 0 OLE Automation
Office C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE16\MSO.DLL {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52} 2 8 Microsoft Office 16.0 Object Library

 

       

发表评论