ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change Sheet references in code? (https://www.excelbanter.com/excel-programming/427356-change-sheet-references-code.html)

Bassman62

Change Sheet references in code?
 
I have some old code that refers to sheet names and I'd like to change these
to the sheet code names.
However, apparently code names are objects of a different type than sheet
Names.
Here's an example of what I'm trying to do:
Change
ThisWorkbook.Sheets("Report").Activate
To
ThisWorkbook.Sheet2.Activate 'Error: Method or Data Member not
found.
This seems elementary but I can't seem to get the syntax correct.
How can I refence a code name of a particula workbook?
Thanks.



Paul C

Change Sheet references in code?
 
Try

ThisWorkbook.Sheets(2).Activate

you can also eliminate the ThisWorkbook (it is implied)

Sheets(2).Activate
--
If this helps, please remember to click yes.


"Bassman62" wrote:

I have some old code that refers to sheet names and I'd like to change these
to the sheet code names.
However, apparently code names are objects of a different type than sheet
Names.
Here's an example of what I'm trying to do:
Change
ThisWorkbook.Sheets("Report").Activate
To
ThisWorkbook.Sheet2.Activate 'Error: Method or Data Member not
found.
This seems elementary but I can't seem to get the syntax correct.
How can I refence a code name of a particula workbook?
Thanks.




Paul C

Change Sheet references in code?
 
if the name of the sheet has been changed in VBA then just the name will work

Sheet2.activate

Keep in mind that the code name for the sheet and the name that appears on
the sheet tab may not be the same.
--
If this helps, please remember to click yes.


"Bassman62" wrote:

I have some old code that refers to sheet names and I'd like to change these
to the sheet code names.
However, apparently code names are objects of a different type than sheet
Names.
Here's an example of what I'm trying to do:
Change
ThisWorkbook.Sheets("Report").Activate
To
ThisWorkbook.Sheet2.Activate 'Error: Method or Data Member not
found.
This seems elementary but I can't seem to get the syntax correct.
How can I refence a code name of a particula workbook?
Thanks.




Bassman62

Change Sheet references in code?
 
Thanks for the reply.
I'd really like to use the sheet code name as the index will not follow if
the sheets are rearranged.
Also, I'd like to know how to refer to the sheet code name of a project that
is not the ActiveWorkbook.
Thanks.

"Paul C" wrote in message
...
Try

ThisWorkbook.Sheets(2).Activate

you can also eliminate the ThisWorkbook (it is implied)

Sheets(2).Activate
--
If this helps, please remember to click yes.


"Bassman62" wrote:

I have some old code that refers to sheet names and I'd like to change
these
to the sheet code names.
However, apparently code names are objects of a different type than sheet
Names.
Here's an example of what I'm trying to do:
Change
ThisWorkbook.Sheets("Report").Activate
To
ThisWorkbook.Sheet2.Activate 'Error: Method or Data Member not
found.
This seems elementary but I can't seem to get the syntax correct.
How can I refence a code name of a particula workbook?
Thanks.






Bassman62

Change Sheet references in code?
 
Thanks Paul.
After more research, I think that I cannot refer to sheet code names outside
of the active workbook.
Thanks again for the prompt reply.


"Paul C" wrote in message
...
if the name of the sheet has been changed in VBA then just the name will
work

Sheet2.activate

Keep in mind that the code name for the sheet and the name that appears on
the sheet tab may not be the same.
--
If this helps, please remember to click yes.


"Bassman62" wrote:

I have some old code that refers to sheet names and I'd like to change
these
to the sheet code names.
However, apparently code names are objects of a different type than sheet
Names.
Here's an example of what I'm trying to do:
Change
ThisWorkbook.Sheets("Report").Activate
To
ThisWorkbook.Sheet2.Activate 'Error: Method or Data Member not
found.
This seems elementary but I can't seem to get the syntax correct.
How can I refence a code name of a particula workbook?
Thanks.







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

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