51Testing软件测试论坛

标题: QTP用VBS函数无法读取EXCEL表中的值 [打印本页]

作者: caton_test    时间: 2009-12-7 16:02
标题: 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
set strTCname = GetCellValue(excelSheet,,1,1)
参数个数
作者: ljdfdd    时间: 2009-12-7 17:44
GetCellValue(excelSheet,,1,1)
多了一个逗号
作者: leeyongbo    时间: 2009-12-7 18:16
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




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2