Adding and removing References to other Workbooks / Addins
Sub AddReference()
Dim Reference As Object
On Error GoTo ErrMsg
With ThisWorkbook.VBProject
For Each Reference In .References
If Reference.Description Like "SyslogReports" Then Exit Sub
Next
.References.AddFromFile "C:\Documents and Settings\dtayl211\Application Data\Microsoft\AddIns\Syslog Reports.xla"
'.References.AddFromGuid "{0D452EE1-E08F-101A-852E-02608C4D0BB4}", 22, 0
End With
Exit Sub
ErrMsg:
MsgBox "Object Library Not Registered on this machine"
End Sub
Sub RemoveSpecifiedReference()
' This example removes 'PowerPoint' reference
' from ThisWorkbook.VBProject .
' Instead of 'ThisWorkbook' you can work with ActiveWorkbook.
'--
Dim ref As Variant
Dim i As Integer
'--
With ThisWorkbook.VBProject
For i = .References.Count To 1 Step -1
Set ref = .References(i)
If Not ref.BuiltIn Then
'MsgBox ref.Name
' Customize Reference name
If ref.Name = "SyslogReports" Then
MsgBox ref.Name
' uncomment the following code line
.References.Remove ref
End If
End If
Next i
End With
End Sub