Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove/add missing reference from VBA

Status
Not open for further replies.

Mblink

Programmer
Jan 23, 2008
1
NL
I have a project that uses the freeware program PDF Creator to generate a PDF from a report.

Normally, all our workstatioins have PDF Creator installed, but if this is not the case, VBA starts acting out.

PDF creation is not mandatory for the program, I also export a Excel copy, but I rather have both.

What I want to do is the following:
- When the program starts, detect if PDF Creator is installed and if it is referenced in VBA
- When not installed, remove the reference to PDF Creator and set a public variable, so the program 'knows' PDF Creator is not present. In the code I can then prevent PDF's form being created.
- When installed and not referenced, relink the reference

I have found a piece of code on this forum to check and detach missing references. The problem there is that if a reference is missing, an error is generated when accessing the Name property of the reference. So there is no way to know if the missing reference is indeed PDF Creator or some other reference.

Does anyone have ideas how to solve this?

 

Adding a reference speeds up code during execution and helps with the intellisense. A MISSING reference is a pain.
If you don't use early bind, late bind overcomes the MISSING problem or not installed dlls but geuss what it adds some delay.

So during startup use late binding to create a dummy pdf and if Error = 0 then success else disable that feature.
 
You can enumerate the references in a code module by doing something like this:

Dim ref As Reference
Dim strxxx As String
For Each ref In CurrentProject.Application.References
strxxx = ref.FullPath
Next

In your case, you might want to check out the IsBroken property before you try to look at other stuff.

If you look at all of the ones where IsBroken is false, and don't find your guy, then you know it's broken...

Tranman

"Adam was not alone in the Garden of Eden, however,...much is due to Eve, the first woman, and Satan, the first consultant." Mark Twain
 
In a case like this, during development I use a reference so I get the benefit of intellisense, and then when I release it I switch to late binding. I find that is less prone to error than having to deal with broken references.

Late binding is of course not as efficient but then who among us can detect the extra milli-seconds?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top