Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Feb 2008
    Posts
    99
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Generate a list of worksheets

    I know it has been discussed before, but I simply cannot find the discussion.

    I need a list of all the worksheets in a file. How to do it?

    And, is there a way to generate the list "externally"? By that I mean that I have a bunch of spreadsheet files, and I want a list of the worksheets in each file.
    [I have been here for years; I had to get things restarted]

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    This will put the list of worksheets in the activesheet
    Code:
    Option Explicit
    Sub GetWorksheets()
        Dim wkb As Workbook
        Dim wks As Worksheet
        Dim lRow As Long
    
        lRow = 1
        Cells(lRow, 1) = "Workbook"
        Cells(lRow, 2) = "Worksheet"
        
        For Each wkb In Workbooks
          For Each wks In wkb.Worksheets
            lRow = lRow + 1
            Cells(lRow, 1) = wkb.Name
            Cells(lRow, 2) = wks.Name
          Next wks
        Next wkb
      MsgBox "Done"
    End Sub
    If you want ALL the Sheets (you only asked for worksheets, which do not include Chart Sheets) change the wks dim to
    Dim sht as variant

    and the line using each wks to
    For Each sht In wkb.Sheets

    Steve
    PS also change the header:
    Cells(lRow, 2) = "Sheet"

  3. #3
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    The previous code assumes all teh workbooks are already opened. If you want to select a list workbooks you can adapt the code at http://windowssecrets.com/forums/sho...l=1#post931909 which is a general procedure for selecting and opening up workbooks. You can open each one, list the sheets and then close the each workbook...

    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •