ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Control on different sheet than the executable (https://www.excelbanter.com/excel-programming/372926-control-different-sheet-than-executable.html)

BearTrap3

Control on different sheet than the executable
 
I need to replace ActiveSheet with the sheet name but I want the user to be
able to change the worksheet name without messing up the macro. Any
suggestions?

Tom Ogilvy

Control on different sheet than the executable
 
possibly use the codename of the sheet. In the project explorer you see two
names

sheet1 (sheet1)

sheet1 is the code name

the name in () is the tab name.

you use the code name like

sheet1.Range("A1")

and the tab name you already would be familiar with
Worksheets("Sheet1").Range("A1")

if you renamed the tab to Dog it would be
Sheet1.Range("A1")
Worksheets("Dog").Range("A1")

see - the codename doesn't change.

--
Regards,
Tom Ogilvy


"BearTrap3" wrote:

I need to replace ActiveSheet with the sheet name but I want the user to be
able to change the worksheet name without messing up the macro. Any
suggestions?


Jim Thomlinson

Control on different sheet than the executable
 
What you want to use is the code name...

sheets("Sheet1").select
is the same as
Sheet1.Select
If they change the tab name then the first statement would bomb but the
second statement would not since the user has no ability to mess with the
code name...
In the VBE you will see all of the sheets listed something like this

Sheet1(mysheet)
Sheet1 is the code name and mysheet is the tab name.
You can change the code name by looking at the properties of the sheet and
the first item (Name) is the code name. If you change this then you will see
shtWhatever(mysheet) in project explorere in the VBE... Now you would refer
to the sheet as
shtWhatever.Select

--
HTH...

Jim Thomlinson


"BearTrap3" wrote:

I need to replace ActiveSheet with the sheet name but I want the user to be
able to change the worksheet name without messing up the macro. Any
suggestions?



All times are GMT +1. The time now is 07:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com