LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default Scope, Public Vars, Referenced workbooks

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.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
scope of public variables Janis Excel Programming 6 September 15th 06 09:05 AM
Different Behaviour of Public Object Vars in Worksheets vs. Add-In Etienne Excel Programming 0 January 4th 06 02:13 PM
Public variables and scope Dennis Benjamin Excel Programming 3 December 2nd 05 04:41 AM
Scope of a public variable Jos Vens Excel Programming 0 November 24th 03 10:08 AM
Scope of Public Variable Dkline[_2_] Excel Programming 9 October 22nd 03 04:53 PM


All times are GMT +1. The time now is 10:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"