determine what sheet user is viewing

  • Thread starter Thread starter Elias
  • Start date Start date
E

Elias

This is probably very simple.

How can I make VBA know what sheet the user is viewing at the time they
activate a macro?

For instance, if they are looking at sheet 17, I want the macro's dialog box
to customize itself to limit its choices to those relevant to sheet 17. I
can do the customization, but don't know the 'if worksheet 17 is active
then...' command.

Thanks.
 
If ActiveSheet.Name = "theName" Then
-or-
If ActiveSheet.CodeName = "theName" Then

Will serve your purpose.

The ".Name" property will give the name that is displayed on the SheetTab.
The ".CodeName" property will give the internal name of the sheet (e.g.
Sheet1, Sheet2, etc.), which can't be changed by the user. If the user
happens to rename the sheet, your macro will probably break if you use
".Name".

Troy
 
Back
Top