ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Worksheet and workbook name question. (https://www.excelbanter.com/excel-programming/295592-re-worksheet-workbook-name-question.html)

Bob Phillips[_6_]

Worksheet and workbook name question.
 
With worksheet, you can use the codename property. If you go into the VBE,
and look at the Microsoft Excel Objects, the codename is the left of the 2
name pairs. It is usually of the form Sheet1(Sheet1), but if the user
changes the name to mySheet, it would show as Sheet1(mySheet).

You would address the sheet like so

Sheet1.Range("A1")

etc.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Mark" wrote in message
...
What is the proper way to refer to a workbook and/or a worksheet within

VBA such that the code remains unaffected if the user changes either the
object name or the sheet's tab position?

Thanks

Mark




TH[_3_]

Worksheet and workbook name question.
 
And you can always refer to the workbook containing the macro that is
running with the ThisWorkbook keyword as in:

ThisWorkbook.Sheet1.Range("A1")

TH

On 4/19/04 14:56, in article , "Bob
Phillips" wrote:

With worksheet, you can use the codename property. If you go into the VBE,
and look at the Microsoft Excel Objects, the codename is the left of the 2
name pairs. It is usually of the form Sheet1(Sheet1), but if the user
changes the name to mySheet, it would show as Sheet1(mySheet).

You would address the sheet like so

Sheet1.Range("A1")

etc.



Tom Ogilvy

Worksheet and workbook name question.
 
if the user changes either the object name or the sheet's tab position

I interpreted the object name to be the codename, but you may be right since
he didn't mention the tab name.

--
Regards,
Tom Ogilvy

"Bob Phillips" wrote in message
...
With worksheet, you can use the codename property. If you go into the VBE,
and look at the Microsoft Excel Objects, the codename is the left of the 2
name pairs. It is usually of the form Sheet1(Sheet1), but if the user
changes the name to mySheet, it would show as Sheet1(mySheet).

You would address the sheet like so

Sheet1.Range("A1")

etc.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Mark" wrote in message
...
What is the proper way to refer to a workbook and/or a worksheet within

VBA such that the code remains unaffected if the user changes either the
object name or the sheet's tab position?

Thanks

Mark







All times are GMT +1. The time now is 10:38 PM.

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