Foreach worksheet

  • I've got a fixed number of excel workbooks from which I need to extract data into a fixed number of tables- however, there are varying numbers of worksheets in each workbook. I know to do a foreach on each file (workbook), but I can't seem to create a foreach object in a file. Is there an iterator for worksheets (/tables) in a workbook (object)?

  • I'm assuming you have a reference set to the excel library so you can access its types.

    so the following would work

    Dim MySheet as Excel.Worksheet

    Dim MyBook as Excel.Workbook

    MyBook:="C:\temp\book1.xls"

    For Each MySheet in MyBook.Worksheets

    ' Do stuff here

    Next

    This is for Excel 2000.

    HTH,

    D'Arcy

  • I just found this on the MSDN Site. Hope it helps...

     

    http://msdn2.microsoft.com/en-us/library/ms345182.aspx

     

     

  • both of you are amazing, thanks so much

  • We know!

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply