Quantcast
Channel: Discussion on 10 ways to reference Excel workbooks and sheets using VBA
Viewing all articles
Browse latest Browse all 5

How to delete sheet by codename?

$
0
0
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).DeleteExplanation: 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 StringsSheetName = VBobject.Properties(7) Worksheets(sSheetName).Delete

Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>