View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_3_] Jim Thomlinson[_3_] is offline
external usenet poster
 
Posts: 983
Default setting object variable

For referencing sheets you can do that directly by renaming the Code Name for
the sheet. In the properties window of the VBE (with Sheet1 selected) you
will see the first listed property is (Name). Change this from Sheet1 to
shtMySheet. In your code you can now reference the sheet directly.

Sheets("Sheet1").Select 'Note intelisense does not work here with "."
shtMysheet.Select 'Note intelisense does work here with "."

will do the exact same thing. The difference is that if the user changes the
tab name from Sheet1 to something else your code will crash. Using shtMySheet
your code will be fine because the user can not change the code name (unless
the go to the VBE).

In your example you have declared codes as worksheets when I think you meant
worksheet. You can pass a worksheet as arguments from one procedure to the
next.

HTH

" wrote:

i am looking for some advice on object variables. I have a module with
two sub routines in it. i have the following object variables at
module level

dim codes as worksheets

i want to use this variable in both subs, and the value(worksheet) will
be the same, so do i have to set the variable in both subs,
set codes = worksheets("sheet1)
this is what i am doing at the moment but i am not sure if this is
correct or good programming.

regards
chris