Public Curiosity

B

BillCPA

Just curious about using 'Public' to define variables. Is there a 'more
correct' place to list variables that you want used by all modules in a
project? Module 1? Form Code module (if you are using a menu)? Completely
separate module?

Also curious about how VBA works here. Does it read through all modules
when you open a project and pull the 'Public' variables? Or do you have to
use code in a particular module before it picks up any variables listed in
that module?
 
C

Chip Pearson

Public variables are typically placed in a standard code module.
It doesn't matter which code module. If you have only one module,
put them there. In a large project, you might want to devote a
module exclusively to public variable. This would be done only
for organizations -- it would have no impact on execution of
code.

Don't put Public variables in the ThisWorkbook module, a
userform's code module or a worksheet's code module unless you
have good reason to do so and you know what you're doing.

VBA will recognize all public variables at the same time. You
don't have to run code in a module for that module's public
variables to be 'recognized'.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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