Consulting

Results 1 to 3 of 3

Thread: How can I use the contents of a variable in several separate subroutines?

  1. #1

    How can I use the contents of a variable in several separate subroutines?

    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

  2. #2
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Hey John, Welcome to VBAX

    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 )

    Good luck!




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #3
    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.
    ttfn

    Kicker

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •