In project explorer which name is the codename?

cellist

New Member
Joined
Jan 6, 2008
Messages
23
A reputable source states "...The first name for each worksheet outside the parentheses is sheet code name . In nearly all circumstances in VBA, you can use the code name anywhere you would normally use Worksheet("SheetName").

The following code shows

MsgBox "MAIN.Name OK"
MsgBox "sheet1.name error"
Code:
Sub check_name()
  Debug.Print Worksheets("MAIN").Name
  MsgBox "MAIN.Name OK"
  On Error GoTo NAME_ERROR:
  Debug.Print Worksheets("sheet1").Name
  On Error GoTo 0
NAME_ERROR:
 MsgBox "sheet1.name error"
End Sub

Have I got it wrong? Or does the reputable source have it wrong?
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Not certain what you are trying to achieve.

Hope this clears things up.

Code:
Sub check_name()  
  Debug.Print Worksheets("MAIN").Name
  MsgBox Worksheets("MAIN").Name & " OK"
  On Error GoTo NAME_ERROR:
  Debug.Print Worksheets("sheet1").Name
  On Error GoTo 0
NAME_ERROR:
 MsgBox Sheet1.Name & " error"
End Sub
 
Last edited:
Upvote 0
Hello cellist,

The worksheet has 2 names: The friendly name that you see on the tab and the code name which assigned by the application when the sheet is created. The friendly name can be changed. The code name is read only and can not be changed.

You can access either name by using the correct property.
Code:
Sub Test()
    MsgBox "The ActiveSheet Name is '" & ActiveSheet.Name & "'" &  vbLf "The Code name is '" & "'" & ActiveSheet.Codename
End Sub
 
Upvote 0
In the Project Explorer the tab name is the one in brackets, the other name is the codename.

For example here, the codename is Sheet1 and the tab name is MAIN.

?Microsoft Excel Objects
|---- Sheet1 (MAIN)
 
Last edited:
Upvote 0
I'm just trying to understand how the two names show up in Project Explorer, as what my "reputable source" says doesn't seem to match what I'm seeing on my system.

Is the code you are showing your code? Is that what you "hope clears things up"? But isn't it the same as the code I posted?

Thanks.
 
Upvote 0
In Project Explorer the tab/sheet name is in brackets, the codename isn't.


?Microsoft Excel Objects
|---- codename (sheetname)
 
Upvote 0
"Sheet1.Name" is the same as "Worksheets("MAIN").Name" in your example.

My previous was (incorrectly) trying to demonstrate this, and also show that:

Code:
MsgBox Sheet1.Name & " error"

is not the same as

Code:
MsgBox "sheet1.name error"

The first returns "MAIN error" and the latter "sheet1.name error"
 
Upvote 0
Yes, I see that your code demonstrates which name is the code name.
But when I run Debug.Print Worksheets("sheet1").name to check that I can use either the tab name or the code name, I get an error that implies that "sheet1" isn't defined--9Subscript out of range. The same command with "MAIN" gets a different message--438Object doesn't support this property or method
Does that seem odd to you?

Thanks for your reply.
BTW, I'm guessing from your signature that Leith rhymes with faith?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top