Adding References from VBA

Did you ever wish you could bypass the Tools > References dialog entirely when adding references in Access? Automate the process with some simple VBA.

Adding References from VBA

To use early binding, you must add References to your VBA project.

Go to Tools > References... to do this manually from the VBA editor.  

But what if you want to add those references programmatically, via VBA?  To do this, you can use the AddFromGUID method of the Access Application References collection.

'Add a reference to the Microsoft Scripting Runtime
References.AddFromGUID "{420B2830-E718-11CF-893D-00A0C9054228}", 1, 0

Finding GUIDs for References

That's great and all...but how are you supposed to find the GUIDs in the first place?

The simplest approach is to manually add the reference to your project, then cycle through all the project references and print the required information to the Immediate Window.  In fact, you can use the following one-liner to print the required info directly from the Immediate Window:

For Each ref In References:?ref.Name, ref.GUID, ref.Major, ref.Minor:Next

External references

References.AddFromGUID method (Access)
Office VBA reference topic

Referenced articles

Early Binding vs. Late Binding: The Essential Guide for VBA Developers
The Absolute Minimum Every VBA Developer Absolutely, Positively Must Know About Early and Late Binding in COM (No Excuses!)

All original code samples by Mike Wolfe are licensed under CC BY 4.0