开发者

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 A开发者_如何转开发s 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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜