View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
LenB LenB is offline
external usenet poster
 
Posts: 25
Default listing all sheets in all workbooks in a directory

This will do that.

Sub ShowSheets()

Dim strFileName As String
Dim wkbBook As Workbook
Dim I As Integer

'results will go in the active sheet of this workbook
ThisWorkbook.Activate
Range("A1").Activate
'loop thru all xls files in c:\test
strFileName = Dir("C:\test\*.xls")
Do While Len(strFileName) 0
Set wkbBook = Workbooks.Open(FileName:="C:\test\" & _
strFileName, ReadOnly:=True)
For I = 1 To wkbBook.Worksheets.Count
ThisWorkbook.Activate
ActiveCell.Value = wkbBook.Name
Cells(ActiveCell.Row, 2).Value = wkbBook.Worksheets(I).Name
ActiveCell.Offset(1, 0).Activate
Next
wkbBook.Close
'gets the next file. When no more, returns empty string
strFileName = Dir()
Loop

End Sub




Todd Huttenstine wrote:
Hey

I need to list all the worksheets in all the workbooks in a specfic
directory.

I need it to look in C:\Test and list the Workbook name and the sheet
name next to it. For example:
Workbook1 - Sheet1
Workbook1 - Sheet2
Workbook1 - Sheet3
Workbook1 - Sheet4
Workbook2 - Sheet1
Workbook2 - Sheet2
Workbook2 - Sheet3

What is the code fo rthis?
Thanks
Todd