Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Reference Libraries

I'm new to VBA and have been throwing together a small macro application for the Office. We've got about 80 users on essentially identical PC setups, and it will be accessed by all but a few users.

I've been playing around with some automation of accessing web pages using the Web Services references, and I've also loaded the Microsoft Scripting Runtime references into the project. I attempted to run it on a test PC and it complained that there were missing references.

I don't particularly want to go around 80 PCs and manually load the references.

My question, basically, is how should I manage the distribution of this macro-app to 80 odd users so as to ensure that the references will load every time for every user.

Thanks!

like image 266
user51498 Avatar asked Jan 06 '09 20:01

user51498


People also ask

How do I add a reference library in VBA?

To add an object library reference to your project Select the object library reference in the Available References box in the References dialog box and choose OK. Your Visual Basic project now has a reference to the application's object library.

What are references in VBA?

VBA allows you to add an object library or type library reference to your project, which makes another application's objects available in your code. These additions to your VBA project are called references.

How do I enable references in VBA?

Add A Reference Make sure that you click on the workbook you want to add the reference to, and from the VBA editor menu choose Tools -> References. In the displayed list check the box beside your renamed add-in, and then click on OK. You'll see that your workbook now has a new reference to the add-in.

Where are VBA references stored?

In Excel (or other MS Office apps), when you go to the VBA IDE, the Tools, References list shows you currently selected assemblies as well as a list of others you can add by checkmarking them. You can also hit Browse to navigate to a folder containing a . TLB file of your own making.


3 Answers

For the most part, late binding will solve problems with references in VBA, unless you have some unusual references. Most problems are caused by differences in library versions that can be overcome with late binding. With VBA, it is often recommended that you develop with early binding but release with late binding. The main disadvantage of late binding is changing built-in constants to values (speed is no longer the issue it used to be.)

So:

Dim fs As Object 'Instead of FileSystemObject '
Dim xl As Object 'Instead of Excel.Application '

Set fs=CreateObject("Scripting.FileSystemObject")
Set xl=CreateObject("Excel.Application")

'Value instead of built-in constant '
ForReading=2
Set f = fs.OpenTextFile("c:\testfile.txt", ForReading)
like image 141
Fionnuala Avatar answered Oct 07 '22 09:10

Fionnuala


If you have references that your application depends on, that you know are not going to be on the target PCs, then I would strongly recommend you investigate some installer technology.

Using the installer you should be able to install your macro, and install and register all appropriate references / libraries.

There are generally two flavours on windows, Windows Installer based technology and Script based technology.

We use InstallShield for all of our deployment, although there are several options for you to use (there are several discussion on Stack Overflow).

Using windows installer technology, you can build MSI install files, which you are then able to deploy automatically using Group Policy.

like image 29
Jayden Avatar answered Oct 07 '22 07:10

Jayden


Instead of having the documents expose the functionality, make it an add-in for Office (the suite, or the individual apps, your choice). This way, you don't have to deal with references.

Then, just distribute an install package with the add-in which registers the components and registers the add-ins with the appropriate Office apps.

VB6 might be a good idea here, given it's similarity to VBA.

like image 43
casperOne Avatar answered Oct 07 '22 08:10

casperOne