Consulting

Results 1 to 8 of 8

Thread: Enumerate reference GUID's

  1. #1
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location

    Enumerate reference GUID's

    I'm looking for a quick way to build a lookup table for all avaialble references in Excel:

    example:
    Reference_Name GUID Major Minor
    VBA Extensibility {0002E157-0000-0000-C000-000000000046} 5 3

    Stan

  2. #2
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location
    Code to list reference for active WorkBook's reference

    You can select ALL references ...


    [vba]
    Sub Grab_References()
    Dim n As Integer
    Dim x As Integer
    On Error Resume Next
    x = 1
    For n = 1 To ActiveWorkbook.VBProject.References.Count
    Cells(x, 1) = n
    Cells(x, 2) = ActiveWorkbook.VBProject.References.Item(n).Name
    Cells(x, 3) = ActiveWorkbook.VBProject.References.Item(n).Description
    Cells(x, 4) = ActiveWorkbook.VBProject.References.Item(n).Major
    Cells(x, 5) = ActiveWorkbook.VBProject.References.Item(n).Minor
    Cells(x, 6) = ActiveWorkbook.VBProject.References.Item(n).fullpath
    Cells(x, 7) = ActiveWorkbook.VBProject.References.Item(n).GUID
    x = x + 1
    Next n
    Columns("A:G").EntireColumn.AutoFit
    End Sub

    [/vba]

    '
    List all checked GUIDS
    http://vbaexpress.com/kb/getarticle.php?kb_id=713
    Last edited by Emily; 02-28-2007 at 08:56 AM.

  3. #3
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Emily,

    That code gives all checked references. In review, I see I wasn't clear when I said all available references, this would refer to all checked/unchecked. I was thinking I could run a WMI query for ProgID's, but I am not sure I get the correct major and minor.

    The point is to build a lookup table to be used when programmatically inserting code into newly created Workbooks. For example, assume I wanted to create a new workbook and insert a module that used ADOX - and this workbook might be sent to another user, I would need to determine if a reference to Microsoft ADO Ext. 2.8 for DDL and Security

    existed and set it using .addfromGuid() if necessary.

    In theory, the lookup could build as various machines might have references not in the initial list. Also, if a reference in the lookup could not be added on a machine (as the ProgID does not exist in the registry) then the VBA code would not even try to execute.

    Hope this is clearer. Stan

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I don't think that there is any way to get an unchecked references.

  5. #5
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location
    Quote Originally Posted by stanl
    Emily,

    That code gives all checked references. In review, I see I wasn't clear when I said all available references, this would refer to all checked/unchecked.

    You can select ALL references ...

  6. #6
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by xld
    I don't think that there is any way to get an unchecked references.
    I know... that's an Excel Mystery... I keep thinking it's gotta be stored somewhere, anyway, that is why I mentioned the WMI route, easpecially for custom OCX's you might register and add. ITMT: I trust you appreciate the goal here. Stan

  7. #7
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by stanl
    ...and this workbook might be sent to another user, I would need to determine if a reference to Microsoft ADO Ext. 2.8 for DDL and Security

    existed and set it using .addfromGuid() if necessary.

    In theory, the lookup could build as various machines might have references not in the initial list. Also, if a reference in the lookup could not be added on a machine (as the ProgID does not exist in the registry) then the VBA code would not even try to execute...
    just use code to set your reference and add error-handling to tell you if it's not registered on their machine. If not registered, your code could be terminated there...

    Example
    [vba]
    Option Explicit

    Private Sub AddReference()

    Dim Reference As Object

    On Error GoTo ErrMsg
    With ThisWorkbook.VBProject
    For Each Reference In .References
    If Reference.Description Like "Microsoft Forms 12.0 Object Library" Then Exit Sub
    Next
    .References.AddFromGuid "{0D452EE1-E08F-101A-852E-02608C4D0BB4}", 12, 0
    End With
    Exit Sub

    ErrMsg:
    MsgBox "Object Library Not Registered on this machine"
    End Sub
    [/vba]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  8. #8
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by Emily
    You can select ALL references ...
    tedious, and you may appropriate links that are broken, or reference multiple versions of ADO which may screw stuff up [don't ask me why or how, but I have witnessed it]. If I can get the WMI correct, I'll post it.

    Thanx

    Stan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •