Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Actually Renaming an Excel Worksheet. 3

Status
Not open for further replies.

grnzbra

Programmer
Mar 12, 2002
1,273
US
I have an Excel workbook with several worksheets. These name show up in the VBAProject/Microsoft Excel Objects as: SheetName(Label on Tab).

SnipImage_asbnxf.jpg


The VBA wants to work with the sheet name not the label. ie PMSchedule, not PM Schedule. I needed to add a new sheet and ended up with Sheet1(Equipment-Warranty).
The VBA will not work with Equipment-Warranty but will work with Sheet1. How can I change Sheet1 to EquipmentWarranty?
 
Hi,

The VBA wants to work with the sheet name not the label. ie PMSchedule, not PM Schedule.

Not so!

The following are equivalent VBA statements:
Code:
PMSchedule.Activate
Worksheets("PM Schedule").Activate

To change...
Code:
Sheet1.CodeName = "EquipmentWarranty"
EquipmentWarranty.Activate


Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
If it's only a design requirement, you can change code name manually. When you have sheet in project explorer selected (as in your image), change (Name) property in properties window.
Note that code name is a part of vba project, when sheets are added dynamically, project structure is not automatically updated.

combo
 
Thanks to both of you. Combo, you pointed me in the right direction. After spending an unacceptable amount of time looking for it,I had assumed there was no properties window so I had given up looking for one. Since you said that there was a properties window, I continued my search and eventually found it.
Skip, thank you for pointing out that I could use the tab label. I had used that because the original developer had used that Worksheets("") notation but he used it on the Equipment sheet so I didn't realize the difference. This clarifies a lot of things.
Thank you both.
 
Skip,
CodeName property is read-only. Code name can be changed programmatically by hiddden r/w [_CodeName] property.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top