Updating Reference
Hi all,
I am trying to update an old reference with a newer one. I also check whether the link has broken. Here is my code
---------------------------------------------------------------------
Dim i As Integer
Dim vbref As Variant
i = 0
rmv = 0
For Each vbref In ThisWorkbook.VBProject.References
i = i + 1
If vbref.IsBroken Then
rmv = 1
ThisWorkbook.VBProject.References.Remove vbref
End If
Next
'
naam = Mid(ThisWorkbook.Name, 1, Len(ThisWorkbook.Name) - 6)
strg1 = Sheet1.Range("A12").Value & "\" & "SourceCode.dll"
If rmv = 0 Then
MsgBox "Removing old references"
ThisWorkbook.VBProject.References.Remove ThisWorkbook.VBProject.References("SourceCode")
ThisWorkbook.VBProject.References.Remove
ThisWorkbook.VBProject.References(naam)
End If
ThisWorkbook.VBProject.References.AddfromFile strg1
strg2 = Sheet1.Range("A12").Value & "\Rekenen\" & naam & ".dll"
ThisWorkbook.VBProject.References.AddfromFile strg2
---------------------------------------------------------------------
At first it checks whether the link is broken and removes those items (which are my old DLL references). If not broken, then remove them from the VBProject anyway. This occurs in the IF statement (if rmv=0 then). Then it adds the new references. The strings are made up by a cell value (which is the main path), followed by additional data so it makes up a complete path.
My code seems to work good, but this goes wrong: After adding the new references, and I check the references VBProject box (where all references are visible) it still uses the old reference path, not the new one. Is there a way to make sure it uses the new path, as it should?
|