Get name of an Excel worksheet containing code

calendar_today Asked Aug 8, 2013
thumb_up 5 upvotes
history Updated April 16, 2026

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)

  • Me.Name — Refer to Named Ranges
  • Me.Name — Invalid procedure name error
  • Worksheet — Refer to All the Cells on the Worksheet
  • Worksheet — List of worksheet functions available to Visual Basic

Top excel-vba Q&A (6)

+5 upvotes ranks this answer #124 out of 136 excel-vba solutions on this site .