Declare Variable

Z

zapatista66

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
 
G

Geof Wyght

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top