View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Public variable (or Public Const?)

Simply going into debug mode, eg set a break and step through, does not
cause variables to lose scope. However if you press the reset button or do
anything to make your code recompile, such as adding declarations or editing
code in certain ways, would indeed destroy your variables.

Regards,
Peter T

"Brettjg" wrote in message
...
Hi Tim, does that means that if I have a macro go into debug then the
values
will be destroyed? If so how can I preserve them please?

"Tim Williams" wrote:

A variable, once assigned a value, should keep that value as long as it's
in
scope.
Provided of course you aren't doing anything like calling "End"...

If your variables are losing their values then something else is going
on,
which is difficult to diagnose without your code.

Tim



"Brettjg" wrote in message
...
I have my main workbook called "1. FINANCE" with six sheets in it. About
10
other workbooks run off the main one doing diffrent tasks. I've set up
a
Public Variable in a normal module in PERSONAL.xls and set FINbk (whick
is
1.
FINANCE) and all of it's sheets such as F_PERS etc. This code works as
it
should, and the variables are set when FINbk opens, and are cleared
when
it
closes.

However, it seems to me that the Public Variables do not retain their
values
after a run of a few macros. Does that mean that I should be using a
Public
Const instead, and if so won't I get an error msg when I try to set it
for
the first time (1. FINANCE is the master name but when I do a run it
has
the
client's surname attached "1. FINANCE Walkenbach.xls"

Just wrapping my head around the whole Public thing (never did care
much
for
the General Public :). Regards, Brett