Solved

How do I get all Sheet names from Excel

Posted on 2006-06-28
4
264 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net dynamic formulas in runtime 11 74
Set value of dynamically created checkboxlist 2 31
Disable extension 8 36
VB.Net - MemoryMappedFiles - Confirm receipt 2 17
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

14 Experts available now in Live!

Get 1:1 Help Now