View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Selecting a worksheet


Indeed that works, but I think only if the sheet's codename is name is known
and can be hardcoded at design time


You can use code like the following:


Dim S As String
S = "Sheet3"
ThisWorkbook.VBProject.VBComponents(S).Activate




Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Sat, 15 Nov 2008 19:23:01 -0000, "Peter T" <peter_t@discussions
wrote:


"Chip Pearson" wrote in message
.. .
for each ws in worksheets
if ws.codename = "Sheet1" then
ws.activate
exit for
end if
next


No need for all that. If you know the code name of the worksheet you
can use it directly:

Sheet11.Activate ' works regardless of sheet Name and Index


Indeed that works, but I think only if the sheet's codename is name is known
and can be hardcoded at design time and only within the same project (ie
can't reference a sheet that way in some other workbook without a reference)
and there could be compile problems if the sheet is subsequently deleted.

Regards,
Peter T