View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Geof Wyght[_2_] Geof Wyght[_2_] is offline
external usenet poster
 
Posts: 38
Default Declare Variable

Zapatista66,
I could have been more careful in my first reply. This
should help. Declare your global variables at the top of
the module, not inside the SetRefs proc. Like this:

Option Explicit
Global gwksZap As Worksheet
Sub SetRefs()
Set gwksZap = ThisWorkbook.Worksheets("Zapatista66")
End Sub

Then in some other procedure say, Workbook_Open you do:

Private Sub Workbook_Open()
Call SetRefs
gwksZap.Activate
End Sub

I tested this. By the way, I use the Hungarian convention.
So "g" in "gwksZap" stands for "global", That way when you
see the object name in some proc, you know where to look
to see where it is declared.

Good luck!
Geof.
-----Original Message-----

Finally, I have another question:
I wrote your SetRefs procedure in ThisWorkbook, but my

VBA have a lot
of UserForm, Modules. So I have to declare my variable in

each userform
and modules.

I understand that your answer is good for each procedure

in a module,
but I want to declare once to all my VBA (Workbook).

Is it clear enough ?


--
zapatista66


----------------------------------------------------------

--------------
zapatista66's Profile:

http://www.excelforum.com/member.php?
action=getinfo&userid=11956
View this thread:

http://www.excelforum.com/showthread...hreadid=266983

.