ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Declare Variable (https://www.excelbanter.com/excel-programming/312803-declare-variable.html)

zapatista66[_11_]

Declare Variable
 

Finally, I have another question:
I wrote your SetRefs procedure in ThisWorkbook, but my VBA have a lo
of UserForm, Modules. So I have to declare my variable in each userfor
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

--
zapatista6

-----------------------------------------------------------------------
zapatista66's Profile: http://www.excelforum.com/member.php...fo&userid=1195
View this thread: http://www.excelforum.com/showthread.php?threadid=26698


Geof Wyght[_2_]

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

.



All times are GMT +1. The time now is 12:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com