Use of Sheet CodeNames to Select Sheet in Different Workbook
I think Steve has already alluded to this, but the codenames of the
worksheets will not necessarily match the tab order of the the worksheets,
which appears to be what your code presumes.
Your sheets could be as follows:
Tab Order 1 2 3 4 5
CodeName Sheet2 Sheet4 Sheet1 Sheet5 Sheet3
If you have a listing of your native sheet names, set up a nested loop.
First go through your worksheets, and for each worksheet loop through your
listing of native sheets and compare the sheet name against each name in your
native list.
"Randy" wrote:
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?
|