Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 24th, 2005, 05:44 AM
Authorized User
 
Join Date: Feb 2005
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?






Similar Threads
Thread Thread Starter Forum Replies Last Post
By value, By reference watashi C++ Programming 1 October 10th, 2007 11:04 PM
reference. scandalous ASP.NET 2.0 Basics 1 April 9th, 2007 07:29 PM
get reference name demac43 Excel VBA 2 November 20th, 2006 02:35 PM
in need of reference! alialibidad SQL Language 1 June 4th, 2006 05:14 AM
in need of reference! alialibidad ASP.NET 2.0 Professional 0 June 3rd, 2006 04:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.