VBA - programatically set references to type libraries?

Status
Not open for further replies.

Athos

Ars Tribunus Militum
2,438
Subscriptor
Is there a programatic way to set up references to needed type libraries in an Excel VBA macro?

Maybe I should explain why I want to do this. I'll be distributing the macro to a number of people. These are end-user types, so I don't want them to have to open up the VBA editor, find Tools->References, and select the proper type libraries. They are also geographically dispersed so it isn't feasible for me to go to their computers to do it myself.
 

wb

Ars Legatus Legionis
25,208
Subscriptor
So is the macro you are distributing inside an Excel workbook? If so, I'm confused as to why you need to automate Tools->References.

The way you should distribute a collection of Excel macros is via an Add-In. An add-in is really just an Excel workbook saved as an add-in, that you can "protect" from people changing the code, forms, etc, and that if stuck in the right directory (or if you have an installer do some stuff) will automatically load when Excel loads. You can use this, for example, to generate a special toolbar that loads as part of Excel.
 

Athos

Ars Tribunus Militum
2,438
Subscriptor
wb wrote:
So is the macro you are distributing inside an Excel workbook?

Yes, inside a workbook.

wb wrote:
If so, I'm confused as to why you need to automate Tools->References.

Maybe I have the wrong idea here (kinda new at this VBA stuff). I assumed that since I had to set the references on my computer using Tools->References, anyone else who wanted to use the macro would have to do the same thing on their computer. So if I just give them the macro will the references still work as long as they have those type libraries registered?

wb wrote:
The way you should distribute a collection of Excel macros is via an Add-In. An add-in is really just an Excel workbook saved as an add-in, that you can "protect" from people changing the code, forms, etc, and that if stuck in the right directory (or if you have an installer do some stuff) will automatically load when Excel loads. You can use this, for example, to generate a special toolbar that loads as part of Excel.

I think I am partly there. What I have right now is a workbook that will be saved into the user's XLStart directory. There's code in the Auto_Open sub that creates a button on the toolbar when Excel launches and links it to another macro in the workbook. It is hidden (like personal.xls), though there is nothing to keep the user from unhiding it and changing something. I will install the workbook into the XLStart directory over the network, so they wouldn't be aware that the workbook existed. But, if doing it as an add-in will give an extra measure of protection, I'm all for that - I'll read up on it.

akmad wrote:
I'm not sure if this is exactly what you are looking for but this may help.

Not quite, but thanks for the effort. :)
 

wb

Ars Legatus Legionis
25,208
Subscriptor
I think I am partly there. What I have right now is a workbook that will be saved into the user's XLStart directory. There's code in the Auto_Open sub that creates a button on the toolbar when Excel launches and links it to another macro in the workbook. It is hidden (like personal.xls), though there is nothing to keep the user from unhiding it and changing something. I will install the workbook into the XLStart directory over the network, so they wouldn't be aware that the workbook existed. But, if doing it as an add-in will give an extra measure of protection, I'm all for that - I'll read up on it.

An Excel Addin is definitely what you want.
 
Status
Not open for further replies.