Archive of Mr Excel Message Board


Back to Excel VBA archive index
Back to archive home

Worksheet name list

Posted by Kurt on June 29, 2001 7:02 AM
Is there a way to get a list of the worksheet names in a workbook onto one worksheet?

I was just given a file with a large number of worksheets. When you go to Properties under the File menu it gives you a list of worksheets under the Contents tab. What I want is a way to get that list into a worksheet.

Thanks.

Kurt


Check out our Excel VBA Resources

Re: Worksheet name list

Posted by faster on June 29, 2001 7:48 AM
This works pretty good. I wrote it for about the
same reason you need it. It will toggle a sheet
called SheetNames; that contains all of your
sheet names.


Sub ListSheetNames()

Dim NumSheets
NumSheets = Sheets.Count

Application.DisplayAlerts = False
Dim i
For i = 1 To NumSheets + 1
If ActiveSheet.Name = "SheetNames" Then
Sheets("SheetNames").Select
ActiveWindow.SelectedSheets.Delete
Exit Sub
End If
Next i
Application.DisplayAlerts = True

Sheets.Add
ActiveSheet.Name = "SheetNames"
Sheets("SheetNames").Move after:=Sheets(NumSheets + 1)
'MsgBox (NumSheets)



For i = 1 To NumSheets
Range("A" & i) = Sheets(i).Name
Next i

End Sub


Re: Worksheet name list

Posted by faster on June 29, 2001 7:58 AM
Sorry I sent you the wrong code. You better use this instead.

Sub ListSheetNames()

Dim NumSheets
NumSheets = Sheets.Count

Application.DisplayAlerts = False
Dim i
For i = 1 To NumSheets
Sheets(i).Select
If ActiveSheet.Name = "SheetNames" Then
Sheets("SheetNames").Select
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
Exit Sub
End If
Next i

Sheets.Add
ActiveSheet.Name = "SheetNames"
Sheets("SheetNames").Move after:=Sheets(NumSheets + 1)

For i = 1 To NumSheets
Range("A" & i) = Sheets(i).Name
Next i

End Sub


This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.