Open Excel File in Vb.net




            I have an excel file,having lot or micros, connecting to database, doing some complex calculation..inshot that excel file is itself an application.

            Now I want to open that excel in VB.net form, on button click. I prefer to open that excel in vb.net form itself having all the excel tool bar etc, If that is not possible then opening in separate window using excel will also solve my purpose (coz when we open in excel it self we will get all the toolbar option etc automatically)

    Please Help


    Tuesday, April 24, 2007 1:45 AM

All replies

  • The following will open up the the excel sheet in excel - callable from VB.NET




    If you want to embed the excel sheet in a vb.net form, then there is a control which you can put on a form


    In the Visual Studio .NET Evironment, right-click on a toolbox tab and select add/remove items. There should be an Excel Spreadsheet 9.0, 10.0, or 11.0 control depending on your version of Office. I believe it is located under the COM Components tab. Select the control and click OK. The control will then be added to your toolbox


    You can then add this to the form from the toolbox and use the Excel controls methods to load the file you want into the control.


    Wednesday, April 25, 2007 1:13 AM
  • Hi,

              Thanks for the reply, yes i want to open excel sheet in form it self. I tried to use excel spreadsheet control..I am able to add it into my tool bar and drag it on form too..but "how to open an existing excel file" into that contol is still a challange for me..

    Please help


    Wednesday, April 25, 2007 1:21 AM
  • You should be able to use the object browser / intellisense to determine the exact call you need to make to load the worksheet.


    I would guess it would be using a similar object model



    So I would look for methods for the controls which deal with opening files to populate the control.  As I dont have excel on this machine cant give you exact method.



    Wednesday, April 25, 2007 2:32 AM
  • Hi,

         Thanks for reply, Using excel object its quite possible to open file


    Imports Excel.WorkbookClass

    Imports Excel.WorksheetClass

    Imports Excel.ApplicationClass


    Dim xlsApp As Excel.ApplicationClass

    Dim xlsWB As Excel.WorkbookClass

    Dim xlsSheet As Excel.WorksheetClass

    xlsApp = New Excel.ApplicationClass

    xlsApp.Visible = True

    xlsWB = xlsApp.Workbooks.Open("C:\test1.xls")


          but that is opening file in excel it self (new window) not in to the form


    I tried very hard to get any method to open existing excel in our "Microsoft office spreadsheet control"..used object browser/intellisense..but no luck.




    Wednesday, April 25, 2007 5:15 AM
  • Not sure if this has been answered but the following my be helpful to you or any others who view this thread:



    • Proposed as answer by Darth Probius Tuesday, April 17, 2012 2:59 PM
    • Unproposed as answer by Darth Probius Tuesday, April 17, 2012 3:00 PM
    Thursday, April 12, 2012 9:47 PM
  • Hi,

    embedding Excel application into VB.NET form is probably not the best choice because it would be very hard to establish two-way communication between Excel app and your form and code would be dependent on Excel app version, so entire solution wouldn't be flexible (hard to add new functionality) and would have deployment issues.

    Better solution would be to VB.NET import Excel to DataTable and bind DataTable to some grid control like with using this C# / VB.NET Excel library:

    Dim bindingSource = DirectCast(Me.peopleDataGridView.DataSource, BindingSource)
    Dim dataTable = DirectCast(bindingSource.List, DataView).Table
    Dim ef = New ExcelFile()
    Dim ws = ef.Worksheets(0)
    ef.Worksheets(0).ExtractToDataTable(dataTable, ws.GetUsedCellRange(True).Height, ExtractDataOptions.None, ws.Rows(1), ws.Columns(0))

    But since your file is very complex (lot of macros, complex calculations) this might not be possible for you.

    Monday, April 16, 2012 9:08 AM