Discussion on:

Message 5 of 5
0 Votes
+ -
How to delete sheet by codename?
What if you know the worksheet VBobject, but not it's sheet name? How can you delete the sheet? Say the VBobject is Sheet1, and the sheet name is something else UNKNOWN. You cannot say Sheet1.Delete, that's not allowed. So how can you get the sheet name or sheet object, when all you know is the VB object behind the worksheet?

Method 1: ThisWorkbook.Worksheets(VBobject.Name).Delete

Explanation: VBobject.Name returns the worksheet name.

Except this does not always work! SOMETIMES, VBobject.Name does NOT return the sheet name, it returns the VBobject name!

Method 2: VBobject.Properties(7) ALWAYS returns the name of the worksheet. Yes, 7.
Dim sSheetName as String
sSheetName = VBobject.Properties(7)
Worksheets(sSheetName).Delete
Posted by johnywhy@...
Updated - 15th Jun 2011