View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Randy[_10_] Randy[_10_] is offline
external usenet poster
 
Posts: 16
Default Use of Sheet CodeNames to Select Sheet in Different Workbook

Didn't get it to work. The issue is that I have to analyze each single
sheet in the workbook. I have a certain list of sheets that are the
original "native" sheets. Any extra sheets are those that were added
by the user. By looping through each worksheet and comparing each
sheet to my list of "native" sheets, I can determine if it is a new
(i.e. "foreign") sheet. If it is, then I do a series of very simple
steps to the user's sheet so that I doesn't screw up some other things
that I need to do (e.g. I take out all of the user's formulas and
replace them with text).

Here is my basic code:

Dim ForeignSheet as Boolean
Set ForeignSheet = True
For x = 1 to Worksheets.Count
If Worksheet(x).Name = Sheet1.Name Then ForeignSheet = False
If Worksheet(x).Name = Sheet2.Name Then ForeignSheet = False
'repeat this sequence for each of the "native" sheets
Next
If ForeignSheet = True then Do Stuff

The weird thing is that if I replace Sheet1.Name with the exact tab
name of the sheet, the procedure works just fine. However, when I
attempt to use the CodeName method, it doesn't work. I want to refer
to code names rather than tab names to make the macro more bullet proof
and allow the user to change their tab names at their discretion.

Anybody see where I am going wrong?