Hi,
I have VBA integrated into accouting application.
I am trying to remove a broken VBA project reference so that I can add the currently available reference. The broken reference is in the VBProject.References collection but when I use the Remove method I get the error "Object library not registered." When I try to add the correct library I get the error "Name conflicts with existing module, project, or object library." I don't want to use late binding.
Here is code that illustrates this problem.
Const TargetReferenceGUID = "{????????-????-????-????-????????????}" ' Here goes the GUID of my broken reference
Dim TargetReference As Object
Dim ReferenceIndex As Long
Dim Index As Long
' Find existing reference
For Index = 1 To VBAHost.VBProject.References.Count
If VBAHost.VBProject.References(Index).GUID = TargetReferenceGUID Then
ReferenceIndex = Index
Exit For
End If
Next Index
' Delete existing reference
If ReferenceIndex > 0 Then
VBAHost.VBProject.References.Remove VBAHost.VBProject.References(Index)
End If
' Add desired reference
VBAHost.VBProject.References.AddFromGuid TargetReferenceGUID, ?, ?
Does anyone know the solution?
Thanks in advance.
Ilia