Question posted 2013 · +6 upvotes
I have code that resides on a page and references the content of the workbook. When executed from a different worksheet, I would like to get the name of the specific Worksheet containing the code.
I have worksheets that contain data. The code is added to that worksheet and the run – which produces a Summary worksheet. From the Summary worksheet, I would like to run the code on the data worksheet. This means I can’t use ActiveSheet and I would have to reference the data sheet by name.
How can I get the name of the worksheet containing the code without having to hard-code the name?
Accepted answer +5 upvotes
Use the “Me” object.
Me.Name is the property you seek, wich will give you the name of the sheet containing the code regardless the active sheet.
Excel VBA objects referenced (4)
Top excel-vba Q&A (6)
- How to clear the entire array? +58 (2010)
- How to change Format of a Cell to Text using VBA +55 (2011)
- Download attachment from Outlook and Open in Excel +43 (2012)
- Can a VBA function in Excel return a range? +36 (2009)
- 2 Dimensional array from range +34 (2013)
- Hiding an Excel worksheet with VBA +33 (2009)
excel-vba solutions on this site
.