user2835052
user2835052

Reputation: 21

Sheet name from Sheet Code

anyone knows how to get the sheet name from the VBA code on that sheet? i.e. : the code on sheet12 will return name of Sheet12, same code on sheet11 will return name of Sheet11? Thanks.

Upvotes: 2

Views: 1913

Answers (3)

Damien Dambre
Damien Dambre

Reputation: 55

An answer to the issue (= getting the name of the sheet where the code is written, not the name of the active sheet) is Me.Name. If you want the sheet number (=the codename), just use Me.CodeName.

Upvotes: 1

Peter Albert
Peter Albert

Reputation: 17495

There are two properties you can refer to:

  1. .Name: This is the name of the worksheet that you can see in the Excel UI
  2. .CodeName: This is the name of the worksheet that you see in the VB editor

Example:

MsgBox "Name of the current sheet in Excel: " & ActiveSheet.Name & vbCrLf & _
    "Name of the sheet in VB editor: " & ActiveSheet.CodeName

Upvotes: 3

Gary's Student
Gary's Student

Reputation: 96791

This will give the name of whichever sheet is active:

Sub dural()
    MsgBox ActiveSheet.Name
End Sub

Upvotes: 2

Related Questions