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:
If this is what you see in the Project Explorer,

��Microsoft Excel Objects
|---- Sheet1 (MAIN)

then this will give you a 'subscript out of range' error,

Code:
MsgBox Sheets("Sheet1").Name

because Sheets expects the tab name and Sheet1 is the codename.

These will all work.
Code:
MsgBox Sheets("MAIN").Name             ' will show 'MAIN'

MsgBox Sheets("MAIN").CodeName    ' will show 'Sheet1'

MsgBox Sheet1.Name                             ' will show 'MAIN'
 
Last edited:
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
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