dcsimg
Results 1 to 2 of 2

Thread: how to open excel file with vb.net 2005

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    44

    how to open excel file with vb.net 2005

    hi
    On my computer I've VB.net 2005. and also office 2007.
    I try to open an excel file like that

    Imports Excel = Microsoft.Office.Interop.Excel

    Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    Dim xlApp As Excel.Application
    Dim xlWorkBook As Excel.Workbook
    Dim xlWorkSheet As Excel.Worksheet
    Dim range As Excel.Range
    Dim rCnt As Integer
    Dim cCnt As Integer
    Dim Obj As Object

    xlApp = New Excel.ApplicationClass
    xlWorkBook = xlApp.Workbooks.Open("C:\Users\MyName\Documents\Book1.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

    xlWorkBook.Close()
    xlApp.Quit()
    .
    .
    .

    on line 2: xlWorkBook = xlApp.Workbooks.Open...
    I got error: "Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))"

    how do I fix this problem

    thank you

  2. #2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width