Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default codename help

i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default codename help

i ended up using index numbers instead
Worksheets(i).Activate

--


Gary


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default codename help

Try

dim cname as Worksheet
For i = 1 To 12
set cname = sheets("Sheet" & i)
cname.Select
Next



"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default codename help

thanks carlos

--


Gary


"Carlos" wrote in message
...
Try

dim cname as Worksheet
For i = 1 To 12
set cname = sheets("Sheet" & i)
cname.Select
Next



"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default codename help

i think that only works for the sheet name, not the codename

--


Gary


"Carlos" wrote in message
...
Try

dim cname as Worksheet
For i = 1 To 12
set cname = sheets("Sheet" & i)
cname.Select
Next



"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default codename help

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary


This works:

---------------------------
Sub Button4_Click()
Dim i As Integer
For i = 1 To 4
Sheets("Sheet" & i).Activate
MsgBox ActiveSheet.Name
Next
End Sub
-------------------------

Ciao
Bruno


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default codename help

Sub RenameSheets()
Dim sSheet As String
Dim oVBMod As Object
Dim i As Long

With ActiveWorkbook.VBProject
For Each oVBMod In .VBComponents
Select Case oVBMod.Type
Case 100:
If oVBMod.Name < "ThisWorkbook" Then
sSheet =
CStr(.VBComponents(oVBMod.Properties("Codename")). Properties("Name"))
With Worksheets(sSheet)
i = i + 1
.Parent.VBProject.VBComponents(.CodeName) _
.Properties("_CodeName") = "Sheet" & i
'For i = 1 To oVBMod.Properties.Count
' Debug.Print oVBMod.Properties(i).Name
'Next i
End With
End If
End Select
Next oVBMod
End With

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default codename help

That is correct Gary.

Although changeable, the usage for codename assumes it isn't

The alternative (to support variability or to get a list) is to loop through
the objects in the project and pick up the codename property.

See Chip Pearson's code on programming the VBE for insights
http://www.cpearson.com/excel/vbe.htm

and codenames specifically:
http://www.cpearson.com/excel/codemods.htm

although if you are populating a combobox with sheetnames

for each sh in Worksheets
.AddItem sh.name
Next


--
Regards,
Tom Ogilvy

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i think that only works for the sheet name, not the codename

--


Gary


"Carlos" wrote in message
...
Try

dim cname as Worksheet
For i = 1 To 12
set cname = sheets("Sheet" & i)
cname.Select
Next



"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary









  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default codename help

thanks for your help on this, bob

--


Gary


"Bob Phillips" wrote in message
...
Sub RenameSheets()
Dim sSheet As String
Dim oVBMod As Object
Dim i As Long

With ActiveWorkbook.VBProject
For Each oVBMod In .VBComponents
Select Case oVBMod.Type
Case 100:
If oVBMod.Name < "ThisWorkbook" Then
sSheet =
CStr(.VBComponents(oVBMod.Properties("Codename")). Properties("Name"))
With Worksheets(sSheet)
i = i + 1
.Parent.VBProject.VBComponents(.CodeName) _
.Properties("_CodeName") = "Sheet" & i
'For i = 1 To oVBMod.Properties.Count
' Debug.Print oVBMod.Properties(i).Name
'Next i
End With
End If
End Select
Next oVBMod
End With

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary







  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default codename help

This code seems like your going in circles.

If you already have a reference to the component (sheet), then why use it to
find the sheet tab name to use to get a reference to the component which you
already have?

--
Regards,
Tom Ogilvy


"Bob Phillips" wrote in message
...
Sub RenameSheets()
Dim sSheet As String
Dim oVBMod As Object
Dim i As Long

With ActiveWorkbook.VBProject
For Each oVBMod In .VBComponents
Select Case oVBMod.Type
Case 100:
If oVBMod.Name < "ThisWorkbook" Then
sSheet =
CStr(.VBComponents(oVBMod.Properties("Codename")). Properties("Name"))
With Worksheets(sSheet)
i = i + 1
.Parent.VBProject.VBComponents(.CodeName) _
.Properties("_CodeName") = "Sheet" & i
'For i = 1 To oVBMod.Properties.Count
' Debug.Print oVBMod.Properties(i).Name
'Next i
End With
End If
End Select
Next oVBMod
End With

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary









  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default codename help

thanks for the tip.

--


Gary


"Tom Ogilvy" wrote in message
...
That is correct Gary.

Although changeable, the usage for codename assumes it isn't

The alternative (to support variability or to get a list) is to loop
through
the objects in the project and pick up the codename property.

See Chip Pearson's code on programming the VBE for insights
http://www.cpearson.com/excel/vbe.htm

and codenames specifically:
http://www.cpearson.com/excel/codemods.htm

although if you are populating a combobox with sheetnames

for each sh in Worksheets
.AddItem sh.name
Next


--
Regards,
Tom Ogilvy

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i think that only works for the sheet name, not the codename

--


Gary


"Carlos" wrote in message
...
Try

dim cname as Worksheet
For i = 1 To 12
set cname = sheets("Sheet" & i)
cname.Select
Next



"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary











  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default codename help

If you really need the CodeName, not the Sheet name, try
something like

Dim N As Integer
For N = 1 To 3
Debug.Print ThisWorkbook.VBProject.VBComponents("Sheet" &
N).Name
Next N




"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary





  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default codename help

chip:

what i was trying to do was loop all sheets based on the code name. the
sheet names were all changed, but i knew the code names were sheet1 thru
sheet 12. i was trying to concatenate the number onto the end of the word
sheet so i could loop.
i used index number instead, the index numbers are 2 thru 13. just wanted to
use code names in case any sheets were inserted.

i used the index (i) variable because i could not figure out how to select
the sheet(i) by code name.

For i = 2 To 13
Worksheets(i).Activate
ActiveSheet.Unprotect
Range("b4:i56,k4:p56,r4:t56,v4:af56").ClearContent s
ActiveSheet.Protect
Range("a1").Select
Next

--


Gary


"Chip Pearson" wrote in message
...
If you really need the CodeName, not the Sheet name, try something like

Dim N As Integer
For N = 1 To 3
Debug.Print ThisWorkbook.VBProject.VBComponents("Sheet" & N).Name
Next N




"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary







  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default codename help

If the code names are sheet2 to sheet13 then

Sub ABC()
Dim i As Long, sh As Object
Dim sStr As String
For i = 2 To 13
sStr = ThisWorkbook.VBProject _
.VBComponents("Sheet" & i) _
.Properties("Name").Value
MsgBox "Tab name of Sheet" & i & _
" is " & sStr
Next

End Sub

--
Regards,
Tom Ogilvy


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
chip:

what i was trying to do was loop all sheets based on the code name. the
sheet names were all changed, but i knew the code names were sheet1 thru
sheet 12. i was trying to concatenate the number onto the end of the word
sheet so i could loop.
i used index number instead, the index numbers are 2 thru 13. just wanted

to
use code names in case any sheets were inserted.

i used the index (i) variable because i could not figure out how to select
the sheet(i) by code name.

For i = 2 To 13
Worksheets(i).Activate
ActiveSheet.Unprotect
Range("b4:i56,k4:p56,r4:t56,v4:af56").ClearContent s
ActiveSheet.Protect
Range("a1").Select
Next

--


Gary


"Chip Pearson" wrote in message
...
If you really need the CodeName, not the Sheet name, try something like

Dim N As Integer
For N = 1 To 3
Debug.Print ThisWorkbook.VBProject.VBComponents("Sheet" & N).Name
Next N




"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary









  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default codename help

ok, thanks for that, tom. i'll file it away

--


Gary


"Tom Ogilvy" wrote in message
...
If the code names are sheet2 to sheet13 then

Sub ABC()
Dim i As Long, sh As Object
Dim sStr As String
For i = 2 To 13
sStr = ThisWorkbook.VBProject _
.VBComponents("Sheet" & i) _
.Properties("Name").Value
MsgBox "Tab name of Sheet" & i & _
" is " & sStr
Next

End Sub

--
Regards,
Tom Ogilvy


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
chip:

what i was trying to do was loop all sheets based on the code name. the
sheet names were all changed, but i knew the code names were sheet1 thru
sheet 12. i was trying to concatenate the number onto the end of the word
sheet so i could loop.
i used index number instead, the index numbers are 2 thru 13. just wanted

to
use code names in case any sheets were inserted.

i used the index (i) variable because i could not figure out how to
select
the sheet(i) by code name.

For i = 2 To 13
Worksheets(i).Activate
ActiveSheet.Unprotect
Range("b4:i56,k4:p56,r4:t56,v4:af56").ClearContent s
ActiveSheet.Protect
Range("a1").Select
Next

--


Gary


"Chip Pearson" wrote in message
...
If you really need the CodeName, not the Sheet name, try something like

Dim N As Integer
For N = 1 To 3
Debug.Print ThisWorkbook.VBProject.VBComponents("Sheet" & N).Name
Next N




"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i want to loop through 12 sheets, codename sheet1 thru sheet12

why doesn't this work?

i = 1
For i = 1 To 12
cname = "Sheet" & i
cname.Select
Next

--


Gary











Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
string to codename rk0909 Excel Discussion (Misc queries) 4 September 25th 08 10:57 PM
Selecting a sheet by codename Dr.Schwartz Excel Programming 3 September 3rd 04 02:15 PM
Chart property Codename??? theycallhimtom Excel Programming 0 May 11th 04 06:22 AM
Using sheet codename problems Dustin Carter Excel Programming 1 February 20th 04 10:26 PM
Worksheet codename Andy Excel Programming 4 December 2nd 03 04:12 PM


All times are GMT +1. The time now is 01:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"