简体   繁体   中英

Error reading Excel using VB.NET

i have this code to read Excel file

    Dim scheduleFileName As String

    'Creating Excel Object
    Dim fileName As String
    fileName = "E:\Vb Deployment\scheduling\scheduleSheet.xlsx"

    Dim objExcel As New Excel._ExcelApplication
    Dim objWrkBk As Excel.Workbook
    Dim objSht As Excel.Worksheet
    Dim testdata As String

    objWrkBk = GetObject(fileName)
    ' or objWrkBk = objExcel.Workbooks.Open("C:\test.xls")
    objSht = objWrkBk.Worksheets(0)

    testdata = objSht.Cells(1, 1).Value.ToString()

But it give at error on line

objSht = objWrkBk.Worksheets(0)

Error: member not found....

Could you please let me know why I am getting this error and how I could correct it?

Workbook does have a member Worksheets . The only thing that's missing is the typecast

objSht = CType(objWrkBk.Worksheets(0),  Excel.Worksheet)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM