View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Stuart[_25_] Stuart[_25_] is offline
external usenet poster
 
Posts: 2
Default "Private Sub" v "Sub"


"Peter T" <peter_t@discussions wrote in message
...
Hi Stuart,


One thing that is puzzling me is that once a variable is declared inside
one sub, there appears to be no need to declare it inside another,

unless the
"Sub" is a "Private Sub" I don't understand why this is because I am

under
the impression taht a variable declared within a sub is unique to that

sub.

I think you are misunderstanding something here. Unless a variable is
declared at module level you do have to declare similarly named variables

in
each procedure, if you use Option Explicit. Otherwise it's simply an
undeclared variable.


Well, there is something definitely quirky with this workbook. I have
procedures that run just fine with undeclared variables in an "Option
Explicit" module, providing that those variables are declared elsewhere
*Inside* other procedures in the same module. (They are defiantly not
declared at the module level!) Now here is the wacky bit. The procedures
work fine as "Sub" if I make that Sub into "Private Sub" Then the procedure
stops working and asks me to declare!

It would appear that this anomaly is only aparent in this workbook, as I am
unable to repeat it in other workbooks!

Another abnormality. I have noticed that throughout my workbook the
"Address" keyword has turned into "addRess" (notice the upper case
change)


Two points here. First, it's generally recommended not to use the name of

a
keyword as a variable. Suggest change addRess to say sAddr (presumably as
string).


Yes, I totally agree. It would appear that I may (probably) did have a
variable "addRess" at some time in the past. however it *No* longer exists
in this workbook, however, where ever I try to use the "Address" keyword,
the workbook converts it to "addRess" .... It's now driving me up the wall!