AlexanderBB
Well-known Member
- Joined
- Jul 1, 2009
- Messages
- 1,835
- Office Version
- 2019
- 2016
- Platform
- Windows
Hi,
I need to add a reference programicably to Microsoft ActiveX Data Objects 6.1 Library to about 75 workbooks.
Have spent ages trying stuff in Google but nothing seems to work, not even code to display the GUID.
Can someone give me that (or how to get it) , and I propose to try the following (unless there's something better)
Any help much appreciated. Also, any idea what Major and Minor mean in the above ??
I need to add a reference programicably to Microsoft ActiveX Data Objects 6.1 Library to about 75 workbooks.
Have spent ages trying stuff in Google but nothing seems to work, not even code to display the GUID.
Can someone give me that (or how to get it) , and I propose to try the following (unless there's something better)
Code:
Sub AddReference()
'Macro purpose: To add a reference to the project using the GUID for the
'reference library
Dim strGUID As String
'Update the GUID you need below.
strGUID = "{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}"
'Set to continue in case of error
On Error Resume Next
'Add the reference
ThisWorkbook.VBProject.References.AddFromGuid _
GUID:=strGUID, Major:=1, Minor:=0
'If an error was encountered, inform the user
Select Case Err.Number
Case Is = 32813
'Reference already in use. No action necessary
Case Is = vbNullString
'Reference added without issue
Case Else
'An unknown error was encountered, so alert the user
MsgBox "A problem was encountered trying to" & vbNewLine _
& "add or remove a reference in this file" & vbNewLine & "Please check the " _
& "references in your VBA project!", vbCritical + vbOKOnly, "Error!"
End Select
On Error GoTo 0
End Sub
Any help much appreciated. Also, any idea what Major and Minor mean in the above ??