N
Neal Zimm
Hi -
Background: I've made the mistake of writing quite a bit
of code before truly understanding all the key aspects of
scope and add-ins.
After reading the scope, and related topics in Help I didn't find
mention of "ThisWorkbook" being somehow special (except for the
events, of course, which I know are private). I have open
and before close code which is working.
In the General Declarations of the ThisWorkbook object, I have:
Public ThisWbkString As String 'test var
There are two "regular" modules in the same workbook:
Reference, and TestMod1
In TestMod1 I have, but get the msg "variable not identified"
for:
Sub PublicTest()
ThisWbkString = "test a public var's value"
MsgBox ThisWbkString
End Sub
When I move the public declaration to the Reference module's
declarations section, the Sub works as anticpated.
1) So, why did the PublicTest sub fail the first time?
2) The above is a precursor to the real issue, which is
the app I'm working on is in two workbooks, let's call 'em
User.xls and Code.xls. The Code book will eventually become an add-in,
about which I'm learning, but am not there yet. (I have
Walkenbach's 2003 VBA book)
I have a TON of vars in the Code.xls "regular" module declarations section,
which I use to hold constant type 'read only' data which the subs and
functions use. It has 4 modules and I have exact copies of the same
declarations section in each.)
The open event of User opens the code.xls workbook.
Subs sitting in User call subs in code.xls and so far,
it's working.
If I reference code.xls in the User.xls, will I avoid typing a
lot of "Public"s in front of these declared vars, and avoid
the copies of the 'main' declarations section, or am I
better off hurrying up the Make-Code.xls-into-an-AddIn event?
I am leery of referencing a workbook when I know so little about it.
thanks.
Neal Z.
Background: I've made the mistake of writing quite a bit
of code before truly understanding all the key aspects of
scope and add-ins.
After reading the scope, and related topics in Help I didn't find
mention of "ThisWorkbook" being somehow special (except for the
events, of course, which I know are private). I have open
and before close code which is working.
In the General Declarations of the ThisWorkbook object, I have:
Public ThisWbkString As String 'test var
There are two "regular" modules in the same workbook:
Reference, and TestMod1
In TestMod1 I have, but get the msg "variable not identified"
for:
Sub PublicTest()
ThisWbkString = "test a public var's value"
MsgBox ThisWbkString
End Sub
When I move the public declaration to the Reference module's
declarations section, the Sub works as anticpated.
1) So, why did the PublicTest sub fail the first time?
2) The above is a precursor to the real issue, which is
the app I'm working on is in two workbooks, let's call 'em
User.xls and Code.xls. The Code book will eventually become an add-in,
about which I'm learning, but am not there yet. (I have
Walkenbach's 2003 VBA book)
I have a TON of vars in the Code.xls "regular" module declarations section,
which I use to hold constant type 'read only' data which the subs and
functions use. It has 4 modules and I have exact copies of the same
declarations section in each.)
The open event of User opens the code.xls workbook.
Subs sitting in User call subs in code.xls and so far,
it's working.
If I reference code.xls in the User.xls, will I avoid typing a
lot of "Public"s in front of these declared vars, and avoid
the copies of the 'main' declarations section, or am I
better off hurrying up the Make-Code.xls-into-an-AddIn event?
I am leery of referencing a workbook when I know so little about it.
thanks.
Neal Z.