To get the active sheet name in VBA Excel, you can use the following code:
Sub GetActiveSheetName()
Dim sheetName As String
sheetName = ActiveSheet.Name
MsgBox sheetName
End Sub
In the above code, we declare a variable “sheetName” as a string. We then assign the value of the active sheet’s name to this variable using the ‘ActiveSheet.Name’ property. Finally, we display the sheet name in a message box using the ‘MsgBox’ function.
Here’s an example:
Sub Test()
Dim sheetName As String
sheetName = ActiveSheet.Name
MsgBox "The active sheet name is: " & sheetName
End Sub
When you run the “Test” subroutine, it will display a message box with the active sheet’s name. For example, if the active sheet is named “Sheet1”, the message box will show “The active sheet name is: Sheet1”.