Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

list worksheets in a workbook.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mepetey - 10 Nov 2007 20:46 GMT
I have a workbook that has upwards of 50 worksheets. Is there a simple way
of generating a list of those worksheets names?  I don't fancy having to do
it manually?

TIA
Gary Keramidas - 10 Nov 2007 20:58 GMT
you don't say where you want to list them, this will display them in the
immediate window
in the vb editor, do a control-G. if you want them in a specific place, post
back

Sub list_names()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
Debug.Print ws.Name
Next
End Sub

Signature

Gary

>I have a workbook that has upwards of 50 worksheets. Is there a simple way of
>generating a list of those worksheets names?  I don't fancy having to do it
>manually?
>
> TIA
mepetey - 10 Nov 2007 21:20 GMT
Thanks for the fast response. I would like to insert them as a list in a
separate worksheet, and use as a validation list.

.

> you don't say where you want to list them, this will display them in the
> immediate window
[quoted text clipped - 14 lines]
>>
>> TIA
Gary Keramidas - 10 Nov 2007 21:38 GMT
then you can use something like one of these:

Sub list_names()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
Worksheets("Sheet1").Range("A" & ws.Index) = ws.Name
Next
End Sub

or

Sub list_names()
Dim i As Long

For i = 1 To Worksheets.Count
Worksheets("sheet1").Range("A" & i).Value = Worksheets(i).Name
Next
End Sub

Signature

Gary

> Thanks for the fast response. I would like to insert them as a list in a
> separate worksheet, and use as a validation list.
[quoted text clipped - 19 lines]
>>>
>>> TIA
Don Guillett - 10 Nov 2007 21:22 GMT
try this
for i=1 to worksheets.count
cells(i,"a").value=sheets(i).name
next i

Signature

Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@austin.rr.com

>I have a workbook that has upwards of 50 worksheets. Is there a simple way
>of generating a list of those worksheets names?  I don't fancy having to do
>it manually?
>
> TIA
IanKR - 11 Nov 2007 12:40 GMT
> I have a workbook that has upwards of 50 worksheets. Is there a simple way
> of generating a list of those worksheets names?  I don't fancy having to
> do it manually?

This is something I use to generate a Table of Contents sheet in a workbook,
which includes a hyperlink to each sheet:

Sub TableOfContents()

Dim ws As Worksheet, wsTOC As Worksheet
Dim r As Long

   Application.ScreenUpdating = False

   For Each ws In ActiveWorkbook.Sheets

       If ws.Name = "Table of Contents" Then
           Application.DisplayAlerts = False
           ws.Delete
           Application.DisplayAlerts = True
       End If

   Next ws

   Set wsTOC =
ActiveWorkbook.Worksheets.Add(Before:=ActiveWorkbook.Sheets(1))
   wsTOC.Name = "Table of Contents"
   wsTOC.Range("A1") = "Table of Contents"
   wsTOC.Range("A1").Font.Size = 18
   r = 3

   For Each ws In ActiveWorkbook.Worksheets

       If ws.Name <> wsTOC.Name Then
           wsTOC.Hyperlinks.Add _
           Anchor:=wsTOC.Cells(r, 1), _
           Address:="", _
           SubAddress:="'" & ws.Name & "'!A1", _
               TextToDisplay:=ws.Name, ScreenTip:="Link to " & ws.Name
           wsTOC.Cells(r, 1).Value = ws.Name
           r = r + 1
       End If

   Next ws

   Columns("A:A").EntireColumn.AutoFit
   Cells.Font.Name = "Times New Roman"
   Range("A1").Select
   Application.CommandBars("Web").Visible = True
   Application.ScreenUpdating = True

End Sub
mepetey - 11 Nov 2007 13:06 GMT
Thanks to one and all for the help! much appreciated

>> I have a workbook that has upwards of 50 worksheets. Is there a simple
>> way of generating a list of those worksheets names?  I don't fancy having
[quoted text clipped - 48 lines]
>
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.