Keep setting of variables for all macros of a procedure

BBHRVS

Board Regular
Joined
Nov 3, 2005
Messages
94
Hi;

I am using in all the macros of a workbook abbreviations for the worksheets.
Since then, at the beginning of each macro, there was something like :
Set wsh1=Thisworkbook.Worksheets("name1")
Set wsh2=Thisworkbook.Worksheets("name2")
...
I want now to define only once the abbreviations of the worksheets and be able to use them in any macro of the procedure.
I tried with a public sub, but this does not work properly.
What is the correct way to do it ?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi, BBHRVS,

see if this works for you
put this in the workbookmodule
Code:
Private Sub Workbook_Open()
Set wsh1 = ThisWorkbook.Worksheets("name1")
Set wsh2 = ThisWorkbook.Worksheets("name2")
End Sub
and this in a "normal" module
Code:
Public wsh1 As Worksheet
Public wsh2 As Worksheet

Sub test()
wsh1.Select
MsgBox wsh2.Name, 64, "title"
End Sub

kind regards,
Erik
 
Upvote 0
Dear Erik;

This is exactly what I did, but the issue is that during macro testing, any interruption, due to bug or voluntary stop, cancels everything which is stored in the variables. Then it begins quite tiring, as you have to reset the wshts ...
 
Upvote 0

Forum statistics

Threads
1,212,132
Messages
6,106,127
Members
447,996
Latest member
ANDYADAM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top