Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I get all Sheet names from Excel

Posted on 2006-06-28
4
Medium Priority
?
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

618 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