How do I check if a reference is active?

Mescoman

New Member
Joined
Oct 27, 2021
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hey hey people.

I have been using the Microsoft Office Library reference for some of my code, and it seems that it doesnt come installed/activated automatically when the code is ran on other computers. I was wondering if there was a way to check (through the activation of a macro) if the reference (if thats the right thing to call "Microsoft Word 16.0 Object Library") is installed/active, and if its not installed/active to offer a choice to the user to install/activate it.

1639750305550.png


I reached references through this:

1639750473674.png


Many thanks!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You can certainly list all references that have been selected, and I'll show you how to do that in a moment.

However, I would suggest that instead of using early binding you use late binding. In the latter case, the reference gets resolved at run-time, where you can add some error handling.

So, for example, first un-select the reference to the Word object library. Then use the following code. It first checks whether Word is already open. If so, it uses that instance. If not, it opens a new instance of Word. If the Word library isn't available or doesn't exist, a message is displayed saying so, and then it exits the procedure.

VBA Code:
    On Error Resume Next
    Dim wd As Object
    Set wd = GetObject(, "Word.Application")
    If Err <> 0 Then
        Err.Clear
        Set wd = CreateObject("Word.Application")
        If Err <> 0 Then
            MsgBox "Word application is unavailable!", vbExclamation
            Exit Sub
        End If
    End If
    On Error GoTo 0

Now, to list the references that have been selected, first allow access to the VBA project model . . .

VBA Code:
File >> Options >> Trust Center >> Trust Center Settings >> Macro Settings >> Developer Macro Settings >> select Trust access to the VBA project object module

Then try . . .

VBA Code:
    Dim ref As Variant
    For Each ref In ThisWorkbook.VBProject.References
        Debug.Print ref.Name
    Next ref

Hope this helps!
 
Upvote 0
Solution
Hey sorry about taking so long to answer, work has me very busy. When I get time I will review your answer and if it works Ill mark it as a solution. Thank you for taking the time to try and help me!
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top