View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
George Nicholson[_2_] George Nicholson[_2_] is offline
external usenet poster
 
Posts: 170
Default object by variable name

Ricky:
Look at the CodeName property for a Worksheet. It allows you to use the
"design view" name of a worksheet to reference the sheet directly. It is
useful but may require a different approach since I don't think you can use
the CodeName itself to refer to a sheet within a collection object: i.e.,
Worksheets("MyCodeName") won't work like Worksheets("MyTabName") does.
However, it does allow you to use the CodeName as if it were an object in
VBA: MyCodeName.Activate.

Because of this, the specific loop you envision may not be possible.
However, you could do a For..Each loop on the Worksheets collection and then
do a SelectCase on the CodeName within that loop.

--
George Nicholson

Remove 'Junk' from return address.


"Ricky M. Medley" wrote in message
...
I want to call an object by its codename with a variable, rather than by

the
object group the variable name
It would take way too much time and typing to explain why I want to do it
this way....But the main one is; I want to be able to pull up the right
sheet no matter what the user renames the sheet to. And yes...I do want

to
allow the user to do this.

for example...

for i = 1 to 10
sheetname = "sheet" & i
thisworkbook.sheetname.blah.blah
<do this
next i

of course, this method will not work...but has anybody a way to accomplish
the same task, but in a different strategy?

Much appreciated
ricky