LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Global variables - where do you place them?

Good point. One thing to note here is that having both a global declaration
and the local declaration within the procedure are perfectly legal syntax and
will not cause a compile error (In this case you would probably get a run
time error as your object would be nothing). Where you have declared both a
Global and a Local varaible the local supercedes the global and is the
varaible that is used in that procedure.
--
HTH...

Jim Thomlinson


"Tom Ogilvy" wrote:

Dim srcProgramDataInputWs As Worksheet

is declared within you sub so it is local to that sub - not global

Global variable are declared at the top of a general module before any
procedure

Public SrcProgramDataInputWs as Worksheet


However, if you want to use the global version in your sub, you would have
to remove the declaration in the sub.

--
Regards,
Tom Ogilvy



"CRayF" wrote in message
...
OK I'm still trying to get a handle on the VBA methodology,

I've now created some "global" subroutines that are not in Module3 and are
called by the worksheet modules.

I have more than one Sub() in the module3. Many share the same variables
"Dim srcProgramDataInputWs As Worksheet" as an example.
Where do I define Global variables that can be used throughout anywhere in
the module. What about a variable that can be used anywhere in any

worksheet?
This is what I have in one of my modules:

Sub ReBuildProgramSummary(Optional Confirm As Boolean = True)
'
'------------------------------------------------------------------------
' Re-Build Program Summary Template
'------------------------------------------------------------------------

'------- Main File Names used for this WorkBOOK ---------------
'--*** Use Program Input Worksheet as a Master for changes ***
'--------------------------------------------------------------
Dim srcProgramDataInputWs As Worksheet
Dim srcProgramSummaryTemplateWs As Worksheet
Dim srcProgramSummaryWs As Worksheet
Dim srcBettingTemplateWs As Worksheet
Set srcProgramSummaryTemplateWs = Sheets("@TemplateProgramSummary")
Set srcProgramSummaryWs = Sheets("ProgramSummary")
Set srcBettingTemplateWs = Sheets("@TempleteBetting")
Set srcProgramDataInputWs = Sheets("ProgramDataInput")
'--------------------------------------------------------------
'------- Set Variables to Workbook Names ---------------
'--*** Use Program Input Worksheet as a Master for changes ***
'--------------------------------------------------------------

If ActiveSheet.Name = srcProgramSummaryTemplateWs.Name Then
MsgBox "Can't run from Template"
Range("N3").Select
Exit Sub
End If
...more






 
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
Global Variables Ernst Guckel[_4_] Excel Programming 2 May 7th 05 11:10 PM
Global vs Local variables Ken Loomis Excel Programming 1 October 12th 04 05:03 AM
How to put excel macros in a 'global' place. Peter van de Kerkhof Excel Programming 4 March 4th 04 12:05 AM
Global Variables Not Accessible John Baker Excel Programming 5 November 28th 03 01:23 AM
Declaring Global Variables skmr3 Excel Programming 1 July 14th 03 05:54 AM


All times are GMT +1. The time now is 02:05 PM.

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"