Worksheet wide vars
You both know by now that I am new to Excel programming. Still Charlie's
answer was what I was really asking for since I cannot implement K answer.
Thanks Charlie.
Undoubtedly K's answer was more to the point considering the usage of what I
asked. Unfortunately I cannot do what you suggest K because I don't know how
to create a standard module and place my variables inside. So far I've only
written code to the Microsoft Excel Objects part of the project. I can see
the Modules part but I don't know what it's for. I had discovered the Public
Const statement but its description suggested a standard module and clicking
on it wasn't really helpful to me. If it's not boring for you, pls explain
what a standard module is and how to create one. If I knew that, I wouldn't
need to use the Workbook_Open procedure in this case.
"Charlie" wrote:
...and if you need to perform any functions whenever the workbook is open
there is a default function in ThisWorkbook called Workbook_Open.
Select the ThisWorkbook module in VBAProject and click the pull-down that
has "(General)" in it. Select the Workbook function and the Workbook_Open
sub will appear. Whatever functionality you code into this sub will be
executed whenever the workbook is opened.
"K Dales" wrote:
Depending on how often the values change, you may want to use public
constants instead; e.g.
Public Const MyName = "Ken"
Public Const FavoriteColor = vbRed
Public Const Age = 42
Public Const Weight = "None of your business!"
You can just put all of these in a standard module, maybe name it CONSTANTS,
and edit the values when needed.
"DoctorG" wrote:
I wish to have fixed content vars for use in my code in order to avoid using
hardcoded content which would require a lot of editing in case it is
necessary to change a value.
PUBLIC var AS STRING in THISWORKBOOK should do the job.
The question is where can I initialize this var to my desired content and
this initialization be done at workbook startup. How can I define a procedure
that is executed as soon as the workbook is loaded, so that inside it I can
perform any initializations are necessary? Is there a default such procedure
(whose name and existence I obviously ignore...)?
|