Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Magenta Ricci   on Nov 02 In MS Office Category.

  
Question Answered By: Mae Roberts   on Nov 02

You need to use private variables  at the module level to hold your
information.

I.e. associated routines are all kept in a module. At the top of the
module - i.e. after the "Option Explicit" and before the first Sub or
Function - you define your long-lived variables as private. They will have
the same lifetime as the module - i.e. for the whole workbook session for
normal modules and the modules belonging to the individual worksheets.

(For class modules, the module variables will have the same lifetime as the
objects created from the class modules. For form modules, IIRC, the life
will extend from when the individual form is first instantiated until it is
finally unloaded, but across successive show/hide sessions. But be careful
with this type of module - you get a "second copy" of everything when you
instantiate a new instance.)

Avoid public global  variables wherever possible - they are simply not good
programming practice. However, module-level PRIVATE variables are good
practice.

Share: 

 

This Question has 9 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on how to preserve variable value between subroutine calls? Or get search suggestion and latest updates.


Tagged: