undeclared variables in Excel code

S

Scott

Before you send me to the Excel newsgroups, please read on...

We have an Excel macro that reads information from a Visio drawing if -- and
only if -- there is a valid license file on the PC (the operation of the
license mechanism isn't relevant). Because of the calls to Visio, the Visio
type library is included in the references of the Excel VBA project.

If there is not a valid license on the PC, the spreadsheet still opens but
doesn't use any of the Visio methods, i.e., the Visio-related code is
completely bypassed.

Here's the weird part: the Excel code works fine in the non-licensed case if
Visio is installed on the PC. However, it fails with "compile errors" if
Visio is not installed on the PC.

It turns out that the problem is the existence of a couple of undeclared
variables: such simple things as the "i" in "For i = 1 to 10".

When I declare all of the variables, the code works correctly without Visio.

Any idea what's going on here???

Thanks,
Scott
 
P

Paul Herber

Before you send me to the Excel newsgroups, please read on...

We have an Excel macro that reads information from a Visio drawing if -- and
only if -- there is a valid license file on the PC (the operation of the
license mechanism isn't relevant). Because of the calls to Visio, the Visio
type library is included in the references of the Excel VBA project.

If there is not a valid license on the PC, the spreadsheet still opens but
doesn't use any of the Visio methods, i.e., the Visio-related code is
completely bypassed.

Here's the weird part: the Excel code works fine in the non-licensed case if
Visio is installed on the PC. However, it fails with "compile errors" if
Visio is not installed on the PC.

It turns out that the problem is the existence of a couple of undeclared
variables: such simple things as the "i" in "For i = 1 to 10".

When I declare all of the variables, the code works correctly without Visio.

Any idea what's going on here???

VBA isn't a true compiled language and even though you say the Visio
related code is bypassed, that is all that happens, it is just
bypassed, it is still there and has to be close to correct to get
through the parser.
 
S

Scott

Interesting... makes sense to some extent... but I'm still puzzled why the
parser has no problem with an undeclared variable in the presence of Visio
but does in its absence. (Ah, it's the old "relax the rules for Visio
programmers" trick! <grin>)

Thanks, Paul.
 
D

David Parker

Did you declare Option Explicit in your code?

In effect, you have written code against a type library that may, or may
not, be present.
Once the code is error checked, you could change the Visio objects to just
Object, then remove the Visio type library from the references.
Of course, you won't have intellisense for the Visio object model, but you
should have code that is OK for a non-Visio PC.
 

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