Question : How can I programmatically get a list of spreadsheets from a MS Excel workbook?

From a form I have the user browse to and selecet a MS Excel workbook they would like to import data from. I have this part working at this time. I need to have the ability get a list of spreadsheets within the workbook so the user can then specify which spreadsheet they want to import. If I could get the list of worksheets in the workbook, I was thinking of populating a list box with the worksheets and allowing the user to select the one to be imported but if there is a better way I'm all ears.

Answer : How can I programmatically get a list of spreadsheets from a MS Excel workbook?

Dim XL As Excel.Application
Dim WB As Excel.Workbook
Dim WS As Excel.Worksheet
   
FileName = "C:\Blah.xls"
Set XL = CreateObject("Excel.Application")
XL.Application.Workbooks.Open FileName, , True

For Each WS In XL.Worksheets
   'WS.Name is the name of the worksheet
Next
Random Solutions  
 
programming4us programming4us