VBA references

Quite often you need to add some reference to be able to get some code to compile. This is because the code is referencing some external object that the Excel VBA does not know about. Normally you would add these references through a dialogue, like the example below.

Adding references programatically

If you know the details about a reference you can actually add them programatically. This is useful if you are sharing code that has some reference dependency and is the method that will be used in How to update modules automatically in VBA.
Here’s how to get the GUID, and major and minor versions. Now – next you’ll want to know How to add references by guid
https://gist.github.com/brucemcpherson/3425929The above code will produce output like this

The above code will produce ouput like this
{000204EF-0000-0000-C000-000000000046}    VBA            4  0     Visual Basic For Applications
{00020813-0000-0000-C000-000000000046}    Excel          1  6     Microsoft Excel 12.0 Object Library
{00020430-0000-0000-C000-000000000046}    stdole         2  0     OLE Automation
{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}    Office         2  4     Microsoft Office 12.0 Object Library
{3F4DACA7-160D-11D2-A8E9-00104B365C9F}    VBScript_RegExp_55  5 5 Microsoft VBScript Regular Expressions 5.5
{662901FC-6951-4854-9EB2-D9A2570F2B2E}    WinHttp        5  1     Microsoft WinHTTP Services, version 5.1
{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}    SHDocVw        1  1     Microsoft Internet Controls
{3050F1C5-98B5-11CF-BB82-00AA00BDCE0B}    MSHTML         4  0     Microsoft HTML Object Library
{0D452EE1-E08F-101A-852E-02608C4D0BB4}    MSForms        2  0     Microsoft Forms 2.0 Object Library
{2A75196C-D9EB-4129-B803-931327F72D5C}    ADODB          2  8     Microsoft ActiveX Data Objects 2.8 Library
{00000300-0000-0010-8000-00AA006D2EA4}    ADOR           2  8     Microsoft ActiveX Data Objects Recordset 2.8 Library
{F5078F18-C551-11D3-89B9-0000F81FE221}    MSXML2         6  0     Microsoft XML, v6.0
{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}    MSComctlLib    2  1     Microsoft Windows Common Controls 6.0 (SP6)
{0002E157-0000-0000-C000-000000000046}    VBIDE          5  3     Microsoft Visual Basic for Applications Extensibility 5.3

For more tips like this see Get Started Snippets.
In the meantime why not join our forum, follow the blog or follow me on twitter to ensure you get updates when they are available.