efficient 发表于 2011-11-8 10:57:23

VBS 调用了两个excel功能的function 后, 第二个提示路径出错

脚本如下:
运行到QTP_read_Excel(pathway,sheetname,x,y)的时候,提示 could not find the file,实际上是可以找到的,因为我单独运行任何一个关于excel的function都成功,请问改怎么处理

call driver()
call QTP_read_Excel(pathway,sheetname,x,y)
call QTP_RowCount_Excel(pathway,sheetname)
'++++++++++++++driver()++++++++++++++
public function driver()
dim QtApp
dim Status
dim caseName
dim x,oRowCount
set QtApp=createobject("QuickTest.Application")
QtApp.launch
QtApp.visible=true
oRowCount=QTP_RowCount_Excel("E:\DailyWork\2011\08\UMASSScript\Data\Control.xls","PersonDetails")
wscript.sleep(20)
forx=1 to oRowCount
'Call QTP_read_Excel("E:\Control.xls","PersonDetails",x,1)
Status=QTP_read_Excel("E:\DailyWork\2011\08\UMASSScript\Data\Control.xls","PersonDetails",x,1)
If Status="Y" Then
        caseName=Status=QTP_read_Excel("E:\DailyWork\2011\08\UMASSScript\Data\Control.xls","PersonDetails",x,4)
        QtApp.open caseName
        QtApp.Test.Run ,true
        QtApp.Test.Close
        end if
next
QtApp.quit
set QtApp=Nothing
end function
'++++++++++++++++++++++++QTP_read_Excel(pathway,sheetname,x,y)++++++++++++++
Public Function QTP_read_Excel(pathway,sheetname,x,y)
Dim oExcel,oWorkBook,ovalue
set oExcel=createobject("Excel.application")
oExcel.Visible=false
Set oWorkBook=oExcel.Workbooks.Open(pathway)
oWorkBook.worksheets(sheetname).activate
ovalue=oWorkBook.worksheets(sheetname).cells(x,y).value
oExcel.Workbooks.Close
QTP_read_Excel=ovalue
set oWorkbook=nothing
set oExcel=nothing
End function
'++++++++++++++++++++++++QTP_RowCount_Excel(pathway,sheetname)++++++++++++++
public function QTP_RowCount_Excel(pathway,sheetname)
dim oExcel,oWorkbook,oSheet,oRowCount
set oExcel=createobject("Excel.application")
set oWorkbook=oExcel.workbooks.open(pathway)//这里提示找不到pathway
set oSheet=oWorkbook.Sheets(sheetname)
oRowCount=oSheet.usedrange.rows.count
oWorkbook.Save
oExcel.Workbooks.Close
oExcel.quit
QTP_RowCount_Excel=oRowCount
set oSheet=Nothing
set oWorkbook=nothing
set oExcel=nothing
end function

lisongsu 发表于 2011-12-30 17:04:37

建议断点调试下,文件名值是否正常。如果正确,可在方法内加:将oWorkbook.Close 加上;第二观察执行完了第一个方法后,是不是还有excel进程在,如果在的话说明第一个方法读完没有关闭。
页: [1]
查看完整版本: VBS 调用了两个excel功能的function 后, 第二个提示路径出错