caton_test 发表于 2009-12-7 16:02:15

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

dabie 发表于 2009-12-7 16:55:54

set strTCname = GetCellValue(excelSheet,,1,1)
参数个数

ljdfdd 发表于 2009-12-7 17:44:25

GetCellValue(excelSheet,,1,1)
多了一个逗号

leeyongbo 发表于 2009-12-7 18:16:11

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]
查看完整版本: QTP用VBS函数无法读取EXCEL表中的值