Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Import Utility

Status
Not open for further replies.

need2progm

Programmer
Dec 13, 2002
92
US
Does any one know a way to get a collection of Worksheets form an excel workbook?

I want to provide the user a list of the available worksheets in a dropdown list and I am not sure how to get them.

Thanks in Advance for any help you can provide
 
Firstly Import a COM Reference for MS Excel into your project

Code:
Dim oExcel As New Excel.Application
oExcel.Workbooks.Open("c:\downloads\book1.xls")

Dim iCount As Integer = oExcel.Sheets.Count
For i As Integer = 0 To iCount - 1
   Dim sName As String = oExcel.Sheets(i).Name
Next

Code is untested, and it may only work with certain versions of the COM library. I suspect it may not work with version 10.

Sweep
...if it works dont mess with it
 
Thanks for the code example....

So I guess I will use the com object then through it into a ado object.. Will look at this .. Thank you
 
This worked GREAT ..

Private Sub GetExcelWorkSheets(ByVal ExcelBookName As String)
Dim Excel As New Excel.Application
Excel.Workbooks.Open(ExcelBookName)

'add all the sheets name to an arraylist
Dim ExcelSheet As Excel.Worksheet
Dim ExcelSheets As New ArrayList
For Each ExcelSheet In Excel.Sheets
ExcelSheets.Add(ExcelSheet.Name)
Next

'Now databind...


One question.. I added a reference to excel.. the version was 2.3 .. Will this work with non 2003 version of office/excel?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top