The title of this thread pretty much says it all - I would like to know how to open an already created excel spreadsheet (I want the application to launch).
Thanks so much to anyone who has time to respond to this.

The title of this thread pretty much says it all - I would like to know how to open an already created excel spreadsheet (I want the application to launch).
Thanks so much to anyone who has time to respond to this.

check out this article by Microsoft ,
http://support.microsoft.com/default.aspx?scid=kb%3B[LN]%3BQ316934

Copy and paste the URL in your browser

Anyone have another suggestion - the microsoft example is slightly prolix.

Anyone have another suggestion - the microsoft example is slightly prolix.

:)
Dim xlsApp As Excel.Application
Dim xlsWB As Excel.Workbook
Dim xlsSheet As Excel.Worksheet
Dim xlsCell As Excel.Range
Dim xlsDatei As String

xlsApp = New Excel.Application
xlsApp.Visible = True
xlsWB = xlsApp.Workbooks.Open(Path)
xlsSheet = xlsWB.Worksheets(1)
xlsCell = xlsSheet.Range("A1")

Greetings from Wolfskind

Hi there

I used the code as given but I get an error as follows:

System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2147417851
Message="The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"
Source="Interop.Excel"
StackTrace:
at Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)

So far I have wasted an afternoon trying to do this basic thing and I would be wrapped if someone could give me a little shove in the back :-)

Thanks very much!
Rino

Good Info :)

thanks for info..

The title of this thread pretty much says it all - I would like to know how to open an already created excel spreadsheet (I want the application to launch).
Thanks so much to anyone who has time to respond to this.

you can read worksheet like this

xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Open("c:\vbexcel.xlsx")
xlWorkSheet = xlWorkBook.Worksheets("sheet1")

range = xlWorkSheet.UsedRange

For rCnt = 1 To range.Rows.Count
For cCnt = 1 To range.Columns.Count
Obj = CType(range.Cells(rCnt, cCnt), Excel.Range)
MsgBox(Obj.value)
Next
Next


http://vb.net-informations.com/excel-2007/vb.net_excel_2007_open_file.htm

http://vb.net-informations.com/excel-2007/vb.net_excel_read_entire%20_worksheet.htm

Thank you, ian_taylor

Your url really helps me

I need tutorial about crystal report and i find them in the related url in your link

Thank!!! Kids

:)
Dim xlsApp As Excel.Application
Dim xlsWB As Excel.Workbook
Dim xlsSheet As Excel.Worksheet
Dim xlsCell As Excel.Range
Dim xlsDatei As String

xlsApp = New Excel.Application
xlsApp.Visible = True
xlsWB = xlsApp.Workbooks.Open(Path)
xlsSheet = xlsWB.Worksheets(1)
xlsCell = xlsSheet.Range("A1")

Greetings from Wolfskind

I have use this code. But I resive runtime errow "Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))". If anyone know how to dilling with this error please answer

if this " Microsoft Excel 12.0 Object Library " is not displaying under PROJECTS --> ADD REFERENCES how to create that object liberary appear there

Here's what I had to do to get the code samples working.

First (as already mentioned), add the Excel object library as a reference. (You must have Excel installed). Something like this:
Project->Add Reference->COM->Microsoft Excel 12.0 Object Library->OK

Then add these two lines to the top of your program:

Imports Excel = Microsoft.Office.Interop.Excel
Imports Office = Microsoft.Office.Core

So here's my complete sample program (new VB.NET project, added one button):

' Make sure to first go to:
' Project->Add Reference->COM->Microsoft Excel 12.0 Object Library->OK

' Now import classes from reference
Imports Excel = Microsoft.Office.Interop.Excel
Imports Office = Microsoft.Office.Core

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Local variables
        Dim xlsApp As Excel.Application
        Dim xlsWorkBook As Excel.Workbook
        Dim xlsWorkSheet As Excel.Worksheet
        Dim xlsCell As Excel.Range

        ' Initialise Excel Object
        xlsApp = New Excel.Application

        ' Open test Excel spreadsheet
        xlsWorkBook = xlsApp.Workbooks.Open("c:\test.xls")
        ' Open worksheet (can open by number or name)
        xlsWorkSheet = xlsWorkBook.Worksheets(1) ' You could also do it by name: "sheet1"
        ' Read the first cell
        xlsCell = xlsWorkSheet.Range("A1")
        ' Display the first cell
        MsgBox(xlsCell.Text)
    End Sub
End Class

Here's what I had to do to get the code samples working.

First (as already mentioned), add the Excel object library as a reference. (You must have Excel installed). Something like this:
Project->Add Reference->COM->Microsoft Excel 12.0 Object Library->OK

Then add these two lines to the top of your program:

Imports Excel = Microsoft.Office.Interop.Excel
Imports Office = Microsoft.Office.Core

So here's my complete sample program (new VB.NET project, added one button):

' Make sure to first go to:
' Project->Add Reference->COM->Microsoft Excel 12.0 Object Library->OK

' Now import classes from reference
Imports Excel = Microsoft.Office.Interop.Excel
Imports Office = Microsoft.Office.Core

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Local variables
        Dim xlsApp As Excel.Application
        Dim xlsWorkBook As Excel.Workbook
        Dim xlsWorkSheet As Excel.Worksheet
        Dim xlsCell As Excel.Range

        ' Initialise Excel Object
        xlsApp = New Excel.Application

        ' Open test Excel spreadsheet
        xlsWorkBook = xlsApp.Workbooks.Open("c:\test.xls")
        ' Open worksheet (can open by number or name)
        xlsWorkSheet = xlsWorkBook.Worksheets(1) ' You could also do it by name: "sheet1"
        ' Read the first cell
        xlsCell = xlsWorkSheet.Range("A1")
        ' Display the first cell
        MsgBox(xlsCell.Text)
    End Sub
End Class

Thank you soo much glaverty this helps me very much i'll contact u if i enroll with any problem during i'm using this ... THanks again

Dim oxcel As Excel.Application
Dim owb As Excel.Workbook
Dim osht As Excel.Worksheet
Dim ocell As Excel.Range

oxcel= New Excel.Application
oxcel.Visible = True
owb= oxcel.Workbooks.Open(Path)
osht= owb.Worksheets(1)
ocell = osht.Range("A1")

If you are just trying to export rows of a Gridview into Excel, then there is a tutorial on how to do it here.

do you have some code that use Microsoft Excel 11.0 Object Library
as a reference to open excel file to vb.net. . i don't have
reference like this one
Microsoft Excel 12.0 Object Library

This is a great help, but what if I wanted to open a spreadsheet using the excel program? How would I pass along that information to the Excel program? Just a newbie needing help. Thanks in advance. :)

Try this code its 100% working

Add reference "Microsoft Excel 10.0 object library" to your project

then paste the code to your open Excel file button Click event

Private Sub OPEN_EXCEL_FILE_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OPEN_EXCEL_FILE_Button.Click


     
            Dim xlsApp As Microsoft.Office.Interop.Excel.ApplicationClass
            Dim xlsWB As Microsoft.Office.Interop.Excel.WorkbookClass

            xlsApp = New Microsoft.Office.Interop.Excel.ApplicationClass
            xlsApp.Visible = True
            xlsWB = xlsApp.Workbooks.Open("D:\vbexcel.xlsx")'ADD PATH OF YOUR EXCEL FILE IN PLACE OF D:\vbexcel.xlsx
        Catch ex As Exception
            MessageBox.Show("excel file not created/found")
       
End Sub

I'm going to close this thread to avoid further confusion. Please create a new thread to ask your question.

Thread Locked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.