Consulting

Results 1 to 8 of 8

Thread: Excel VBA Project References

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    Excel VBA Project References

    I have a sheet with all the Project references that I want installed on the user's system to enable Excel Macros run correctly.
    I need to go through the list on the GUID worksheet , Column C, and see if its already installed on the Users system.
    If its not installed, I want to install it.

    If an error occurs, I want to have the error written to the worksheet in Column H
    See attached workbook
    Using Office 2007
    Attached Files Attached Files

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Try this


    Option Explicit
    
    Sub CheckReferences()
        Dim i As Long, j As Long
        Dim rGuids As Range
        
        Set rGuids = Worksheets("GUID").Cells(1, 1).CurrentRegion.Columns(4)
        
        For i = 2 To rGuids.Rows.Count
            For j = 1 To ThisWorkbook.VBProject.References.Count
                If ThisWorkbook.VBProject.References(j).GUID = rGuids.Cells(i, 1).Value Then
                    GoTo NextGUID
                End If
            Next j
            Worksheets("GUID").Cells(i, 8).Value = "Missing"
    NextGUID:
        Next I
        
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Hi Thanks:

    I modified the code to ADD the missing References like this;

    Worksheets("GUID").Cells(i, 8).Value = "Missing"
         Gref = Worksheets("GUID").Cells(i, 4).Value
                
         ActiveWorkbook.VBProject.References.AddFromGuid Gref, Worksheets("GUID").Cells(i, 5).Value, Worksheets("GUID").Cells(i, 6).Value
                                     
    NextGUID:
    What I can't figure out is why is
    Microsoft VBScript_Regular Expressions 5.5 not being installed.
    All the other References are OK.

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Sub M_snb()
      sn = sheets("GUID").Cells(1, 1).CurrentRegion
        For Each it In ThisWorkbook.VBProject.References
        c00 = c00 & " " & it.GUID
      Next
    
      For j = 2 To ubound(sn)      
        If instr(c00,sn(j,4))= 0 then thisWorkbook.VBProject.References.AddFromGuid sn(j,4), sn(j,5), sn(j,6)
      Next
      End Sub
    When you use VBA you should avoid any interaction with a worksheet as much as possible.
    Last edited by snb; 05-16-2017 at 02:05 AM.

  5. #5
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Thanks snb:


    Good information.
    However, What I'm trying to figure out is why
    Microsoft VBScript_Regular Expressions 5.5 is not being installed.

    Your code did not execute. It gave an error at

     ThisWorkbook.VBProject.References.AddFromGuid it, sn(j, 5), sn(j, 6)
    it = Empty

    Didn't fully understand the detailed logic of your code. I couldn't see exactly where its determining if a VBProject.Reference is already installed.

  6. #6
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    It should be:
    thisWorkbook.VBProject.References.AddFromGuid sn(j,4), sn(j,5), sn(j,6)

    Both Librareis have the same GUID.
    Probably VBA finds it hard to choose which one to load.

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Quote Originally Posted by simora View Post
    Hi Thanks: What I can't figure out is why is Microsoft VBScript_Regular Expressions 5.5 not being installed. All the other References are OK.


    I've always used AddFromFile


    Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files (X86)\Microsoft Office\Office14\MSPPT.OLB"
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Thanks all.

Posting Permissions

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