PDA

View Full Version : How can I use the contents of a variable in several separate subroutines?



bennyjohn5
04-17-2007, 02:40 PM
Hello,
In my project the user inputs text to an input box. When a separate subroutine tries to access the variable it has become empty. Essentially my question is how do you use the same variable in several different subroutines?
Please help, John

malik641
04-18-2007, 08:30 PM
Hey John, Welcome to VBAX :hi:

Take a look at OZGrid's article on Variable Scope:
http://www.ozgrid.com/VBA/variable-scope-lifetime.htm

It uses Excel as its example, but the concept still holds for all VBA variables (that I know of :rolleyes:)

Good luck!

Kicker
05-11-2007, 11:36 AM
In one of your VBA modules, declare a public variable. Then, when you use the inputbox, assign the value to the public variable. It will always be available and can be changed when the input box is used again or when the vba code changes it.