Read Variable from Another Module

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a sub: Private Sub Worksheet_calculate(). How can I read a variable
from a module that was set at the top of that module:

Option Base 1
Dim TheWb As String

I want to know what the value of TheWb is while in the calculate sub...
 
When refering to variables in other module you just need (or at the very
least should) reference the module and then the variable name to get the
value something like this...

Private Sub Worksheet_calculate()
msgbox Module1.TheWb 'Or whatever the module name is
end sub

Additionally in the module where you declare the variable my preference is
to use the public key word so that I know that the variable is being accessed
from a procedure outside the module

Option Base 1
Public TheWb as String 'Note public instead of just dim

While this is not strictly necessary I like it as a reminder...
 

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

Back
Top