Activate Object Library References in Visual Basic Editor

Learn VBA Macros From General Code Vault Snippets

What This VBA Code Does

This bit of code will allow you to turn on specific VBA reference libraries (I like to call these "languages").  You can use my Display_GUID_Information macro to tell you all the information you need to know about a specific Reference ensuring your users have the proper reference(s) activated.  This will prevent your code from displaying error messages while trying to command outside applications (ie NotePad, Outlook, Internet Explorer, etc..) with your VBA macros.  You can learn how to make Excel communicate with PowerPoint in one of my most popular posts: Teaching Excel How To Speak PowerPoint.  That post can help serve as an intro into exploring cross-application programming.

Sub ActivateReferenceLibrary()

'PURPOSE: Show How To Activate Specific Object Libraries

'Error Handler in Case Reference is Already Activated
  On Error Resume Next
    'Activate PowerPoint Library (version 2.9)
        ThisWorkbook.VBProject.References.AddFromGuid _
          GUID:="{91493440-5A91-11CF-8700-00AA0060263B}", _
          Major:=2, Minor:=9
    'Activate Visual Basic for Applications Extensibility Library (version 5.3)
      ThisWorkbook.VBProject.References.AddFromGuid _
        GUID:="{0002E157-0000-0000-C000-000000000046}", _
        Major:=0, Minor:=0 'Use zeroes to default to latest version

'Reset Error Handler
  On Error GoTo 0

End Sub

How Do I Modify This To Fit My Specific Needs?

Chances are this post did not give you the exact answer you were looking for. We all have different situations and it's impossible to account for every particular need one might have. That's why I want to share with you: My Guide to Getting the Solution to your Problems FAST! In this article, I explain the best strategies I have come up with over the years to getting quick answers to complex problems in Excel, PowerPoint, VBA, you name it

I highly recommend that you check this guide out before asking me or anyone else in the comments section to solve your specific problem. I can guarantee 9 times out of 10, one of my strategies will get you the answer(s) you are needing faster than it will take me to get back to you with a possible solution. I try my best to help everyone out, but sometimes I don't have time to fit everyone's questions in (there never seem to be quite enough hours in the day!).

I wish you the best of luck and I hope this tutorial gets you heading in the right direction!

Chris "Macro" Newman :)