我有这段代码来阅读Excel文件
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()
但它在行上出错了
objSht = objWrkBk.Worksheets(0)
错误:找不到成员....
请您告诉我为什么我会收到此错误以及如何纠正错误?
答案 0 :(得分:1)
Workbook
确实有会员Worksheets
。唯一缺少的是类型转换
objSht = CType(objWrkBk.Worksheets(0), Excel.Worksheet)