PDA

View Full Version : Solved: Sheet names



jmenche
08-30-2007, 11:47 AM
Howdy,

I renamed my sheets in the VBE. What I mean is I changed the (Name) from 'Sheet1' to something more relevant. The actual (visible) Name is the same. Is there a way to reference this "other" name in my code just in case some idiot changes the visible sheet name?

:beerchug:

mvidas
08-30-2007, 12:01 PM
Hi,

Assuming you changed it to "SomethingMoreRelevant" and you're running the code from within that workbook:SomethingMoreRelevant.Range("A1").Value = "Hi" Otherwise, from another workbook: Dim WS As Worksheet
For Each WS In Workbooks("Filename.xls").Worksheets
If WS.CodeName = "SomethingMoreRelevant" Then
WS.Range("A1").Value = "Hi"
Exit For
End If
Next
If some idiot changed the filename too: Dim WS As Worksheet, WB As Workbook
For Each WB In Application.Workbooks
For Each WS In WB.Worksheets
If WS.CodeName = "SomethingMoreRelevant" Then
WS.Range("A1").Value = "Hi"
Exit For
End If
Next
If Not WS Is Nothing Then Exit For
Next

jmenche
08-30-2007, 12:11 PM
CodeName is what I was looking for.

:-)