Solved

How do I get all Sheet names from Excel

Posted on 2006-06-28
4
263 Views
Last Modified: 2012-05-05
Hi,

I am trying to make my VB.NET app look at an Excel sheet and list all of its Worksheet names in a combobox. Can someone show me and example of how I can do this?

Thanks.
0
Comment
Question by:kiranboi
  • 3
4 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 16999698
       Dim XL As New Excel.Application
        Dim XLWB As Excel.Workbook
        XLWB = XL.Workbooks.Open("C:\test.xls")
        Dim Sh As Excel.Worksheet
        For Each Sh In XLWB.Sheets
            ComboBox1.Items.Add(Sh.Name)
        Next
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 16999709
And don't forget to quit the App after everything is done...
   XL.Application.Quit()

0
 

Author Comment

by:kiranboi
ID: 16999726
Is there anyway of doing it through OleDb so I dont have to import Excel?
0
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 500 total points
ID: 16999805

        Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\YOUR_PATH\YOUR_XL_FILE.xls;Extended Properties=""Excel 8.0;HDR=YES;"""
        Dim Cn As New OleDbConnection(ConStr)
        Cn.Open()
        Dim DT As DataTable = Cn.GetSchema("Tables")
        For Each dr As DataRow In DT.Rows
             ComboBox1.Items.Add(dr("TABLE_NAME").ToString.TrimEnd("$"))
        Next
        Cn.Close()
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now