How to declare a Global Varable ? (So different modules in the same Workbook can see it?)

  • Thread starter Thread starter tmb
  • Start date Start date
T

tmb

How do I declare a variable so that it can be seen or accessed from
different modules in a workbook.

I've go a number of Forms and proceed from one to the next as data is
entered.

I need to keep track of several text and integer variables from Form to Form
and Module to Module.

How is this done in vba for Excel ?

thanks for any help - tmb
 
Got it!

Public mySring as String
Public myNumber as Long

So long as you declare it in the Declarations section of a Module. If you do
it from within a procedure it won't be available outside the procedure.

Right?

tmb
 
So long as you declare it in the Declarations section of a
Module. If you do it from within a procedure it won't be
available outside the procedure.

Right?

That's correct, and refers to what is called the 'scope' of a
variable. See that term in VBA help files or a book for more
discussion.


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