Change Location of VBE References with VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all I was wondering if Reference location be changed using vba code I have
tried using Application.VBE.ActiveVBProject.References.AddFromFile but I need
to remove the reference before adding a new one when I try to remove the it I
get an error has one done this before if so can you please help?.
TIA
Charles
 
Hi Charles,

Without seeing your code its not possible to know if it fails because the
code is wrong or fails for some other reason, eg the reference doesn't
exist. Try something like this -

Dim rf As Reference

'With ThisWorkbook.VBProject.References
With Application.VBE.ActiveVBProject.References
On Error Resume Next
Set rf = .Item("ref name to be removed")
If Not rf Is Nothing Then
.Remove rf
Else
' ref doesn't exist
End If
End With

Regards,
Peter T
 
I think my Idea of a reference is wrong?
I am trying to change the location of this file Y:\Quality\GALC system\HTR
support\Turkey\Data Files\msadox.dll to another location can this be done as
nothing I have tried works.
TIA
Charles
 
I think my Idea of a reference is wrong?

Is that a question?

Difficult to understand what you are doing and why you want to change file
location of the dll. However if that's what you are doing, and the dll is an
ActiveX, you will need to re-register the dll. Having done that, providing
the dll is the same version or later as that to which a reference was set in
your project, you shouldn't need to remove and re-add the reference to your
project.

Regards,
Peter T
 
we are supporting a sister company in Turkey and the report programmes that
we build and test here work fine but when we send it you them it wont work
due to references!, I wanted to have the programme know where it is and
change the location.
TIA
Charles
 
I wanted to have the programme know where it is and
change the location.

I don't think the location of the dll is not the issue, is it actually
registered on the target machine.

If it is registered it might be an older version (along the lines I
mentioned previously), have you checked. If so removing (as per example
posted previously) and re-adding the reference might work.

Regards,
Peter T
 
I tried the code you gaive me but I still get an error, their location is in
Trukish and that why it can't fine the dll's and when there is a problem or
they want an upgrade they send it back and we have to manaualy change it.
 
Did you digest this part of my previous post -

What's the answer to this question.

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top