Macro to add/install a reference in VBA

phantom1975

MrExcel MVP
Joined
Jun 3, 2002
Messages
3,962
I have looked everywhere I can and I am unable to find a solution. I have an add-in that I created installed. Cool! The problem I am having is that when I open a workbook, I would like to be able to use the functions and macros in the add-in. No problem! I understand that I have to set a reference to the add-in (even though it is installed) in order to use the functions and macros. No biggie, I set a reference to the add-in and everything works beautifully.

HERE'S THE PROBLEM: I have to manually set the reference each time I open a new workbook. I have about a dozen workbooks that I need to reference this add-in. The trick is that I will be giving many people these workbooks and need to make sure that they all also reference the add-in. Without getting to long-winded, all I am looking for is a macro that will check if a reference exists and if it is activated. If it doesn't exist, it will be added (every user will have a copy of the add-in installed and it is in the same directory on every computer.) If the reference does exist, but it is not activated, I need to have it activated.

I love you.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
To programatically add a reference use code like this:

ThisWorkbook.VBProject.References.AddFromFile "C:\AddIns\MyAddIn.xla"
 
Upvote 0
To programatically add a reference use code like this:

ThisWorkbook.VBProject.References.AddFromFile "C:\AddIns\MyAddIn.xla"

I'm sure that this is what I am looking for. When I run it though, I get the following:

Run-time error 1004:

Programmatic access to Visual Basic Project is not trusted.

Do I need to take them out to dinner a few times first?
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,268
Members
449,149
Latest member
mwdbActuary

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