Thought I'd chuck this on as it's something I use regularly and something I see a lot of other people mentioning in posts....
If you use code reliant on non-standard vb libraries then you can use the GUID for that library to reference it on the workbook being opened - then use the name of the library to remove it again when closing the file. Saves going in and ticking the references everytime!!
The below is what I use when working with ADO - I can not take credit for this as I found it on another forum but thought i'd post it up for others to use.
You can add these to your "ThisWorkbook" Sheet ... will install ADO (2.5 or above) and remove it on open and close of the workbook.
VB:
Private Sub Workbook_Open()
On Error Resume Next
Set ID = ThisWorkbook.VBProject.References
ID.AddFromGuid "{00000205-0000-0010-8000-00AA006D2EA4}", 2, 5
End Sub
VB:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim x As Object
n = Application.VBE.ActiveVBProject.References.Count
Do While Application.VBE.ActiveVBProject.References.Count > 0 And n > 0
On Error Resume Next
Set x = Application.VBE.ActiveVBProject.References.Item(n)
y = x.Name
If y = "ADODB" Then
Application.VBE.ActiveVBProject.References.Remove x
End If
n = n - 1
Loop
End Sub
If you don't know the GUID then reference it (by ticking it) and then run this to list all the active libraries and their GUIDs - adapted from NateO post on Mr E
VB:
Sub Grab_References()
Dim n As Integer
Sheets.Add
ActiveSheet.Name = "GUIDS"
On Error Resume Next
For n = 1 To ActiveWorkbook.VBProject.References.Count
Cells(n,1) = ActiveWorkbook.VBProject.References.Item(n).Name
Cells(n,2) = ActiveWorkbook.VBProject.References.Item(n).Description
Cells(n,3) = ActiveWorkbook.VBProject.References.Item(n).GUID
Cells(n,4) = ActiveWorkbook.VBProject.References.Item(n).Major
Cells(n,5) = ActiveWorkbook.VBProject.References.Item(n).Minor
Cells(n,6) = ActiveWorkbook.VBProject.References.Item(n).fullpath
Next n
End Sub
Hope that proves as useful for others as it has for me.
Bookmarks