"Private Sub" v "Sub"
Hi Stuart,
What are the differences between "Private Sub" and "Sub".
"Private Sub" (or function) can only be called by another within the same
module. If you don't want any of your macros to be called from the Excel
toolbar you could head your modules:
Option Private Module
I am in the process of declaring all my variables in a very large and
complex workbook. (up until now I haven't bothered and am now
suffering from
occasional crashes, I am hoping that declaring all variables and using
"Option Explicit" will cure this prob)
Good idea to use Option Explicit and declare your variables, and fully to
expected data or object type. When done, from vba's main menu, Debug
Compile. It will break on anything that can't be compiled - investigate,
correct and repeat compile until it completes.
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.
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).
Second, when you capitalize a variable in one part of your project, it gets
recapitalized the same way elsewhere. It's either a quirk or extremely
clever depending on your point of view.
Regards,
Peter T
|