Add Remove DLL reference in VB

A

Alex

Further to my previous post on the 10th, i have a few
questions/results to post,

i find it impossible to remove any reference without an
error coming up. I used the following code:

On Error Resume Next
Application.DisplayAlerts = False
With ThisWorkbook.VBProject.References
.Remove .Item("ProgressIndicator")
Debug.Print Err.Number
End With
Application.DisplayAlerts = True
On Error GoTo 0

Application.DisplayAlerts = False
ThisWorkbook.VBProject.References.AddFromFile
("c:\ProgressIndicator.dll")
Application.DisplayAlerts = True

So, in the first instance i delete the reference and then i
add it up again. Please note that in the current procedure
i do not use the dll, the dll is used from another procedure.

So, there are two cases one in which the dll is already
referenced and one in which it is not.

Suppose that it is referenced, then the code in deleteing
the reference comes up with "Can't enter break mode at this
time" and the options "continue" or "end only" are
possible. So i used debug.print err.number to get the error
number, which is zero!

If its not referenced then it goes smoothly through the
"deletion" routine (as there is nothing to delete) and
again comes up with "Can't enter break mode at this time"
"continue" or "end" options. Now, here the strangest thing
happens, i click on end and i have a look at the
references, and the code has added a reference to
"ProgressIndicator.dll" but not on "C:\" but rather on
"C:\windows\System32\". I really don't get and of course
the "ProgressIndicator.dll" does not reside on system32...

I am a bit perplexed, sorry for the big post,
Thanks a lot for your replies,
rgrds,
Alex
 
A

Alex

I 've tried stepping throught the code or just letting it
run, the same thing happens in both cases...
 
R

Rob van Gelder

Tried the code at my end. I get error number 9 if the Reference doesn't
exist - as expected.
I don't get anything about "Can't enter break mode".

Suspecting some sort of corruption.
Suggest you export the module, delete it, import it.
or run Rob Bovey's code cleaner:
http://www.appspro.com/Utilities/CodeCleaner.htm
 
A

Alex

Rob,

thanks for your help, but i doubt that the code is
corrupted, it is a very simple 20 line procedure that works
just fine if you dont programmatically add the reference,
the problem seems to be in adding the reference through
code, i had a look at

http://support.microsoft.com/default.aspx?scid=kb;en-us;155051

but that doesn's solve the problem.

The most amazing thing is that it keeps adding a reference
to c:\windows\system32 and i'm asking it to add it to c:\

it doens't make much sense,

anywayz, thanks for your help.
Alex
 
A

alex

Thinking about what you just said, you might be right in
that before i tried to programmatically add the reference i
added it manually so this may somehow confuse VBA.

How do i permanently delete a reference so that it would
not appear in the tools-references list at all.

By physically deleting the file the list still displays the
reference name, i.e. progressindicator, but when you click
on it it says error in loading dll, unfortunately it
doesn't prompt you to permanently delete ir

thanks,
Alex
 
R

Rob van Gelder

You know how to delete it via automation. The manual way is via Tools |
References.

I don't know of any other way.
 
K

keepITcool

you probably cant do it from within the compiled project itself
i suggest you to put your 'changing' code in another project, and call the
function via an ontime


keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 

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

Top