QTP用VBS函数无法读取EXCEL表中的值
set ExcelApp = CreateExcel()Set excelBook = OpenWorkbook(ExcelApp,"C:\Documents and Settings\Administrator\桌面\login.xls")
set excelSheet = GetSheet(excelBook,"Sheet1")
set strTCname = GetCellValue(excelSheet,,1,1)
到最后一步,getcellvalue的时候,报错:General run error.
下面就是cript中用到的函数
Function CreateExcel()
Dim excelSheet
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Workbooks.Add
ExcelApp.Visible = True
Set CreateExcel = ExcelApp
End Function
Function OpenWorkbook(ExcelApp, path)
On Error Resume Next
Set NewWorkbook = ExcelApp.Workbooks.Open(path)
Set OpenWorkbook = NewWorkbook
On Error GoTo 0
End Function
Function GetCellValue(excelSheet, row, column)
value = 0
Err = 0
On Error Resume Next
tempValue = excelSheet.Cells(row, column)
If Err = 0 Then
value = tempValue
Err = 0
End If
On Error GoTo 0
GetCellValue = value
End Function set strTCname = GetCellValue(excelSheet,,1,1)
参数个数 GetCellValue(excelSheet,,1,1)
多了一个逗号 Set objexcel = CreateObject("Excel.application")
Set oWb = objexcel.Workbooks.Open ("C:\Documents and Settings\Administrator\桌面\login.xls")
Set oSheet = oWb.Sheets("Sheet1")
text = osheet.range(A1).value
msgbox text
页:
[1]