QTP 怎么判断一个文件是否存在

来源:互联网 发布:java工程师证书考试 编辑:程序博客网 时间:2024/04/27 20:51

判断一个文件是否存在需要用FileSystemObject:

sSourceFile="C:\Source.xls"

set fso=CreateObject("Scripting.FileSystemObject")

xlApp=CreateObject("Excel.Application")

bFileExist=fso.FileExists(sSourceFile)

if bFileExist then

set  xlWorkbook=xlApp.workbooks.open(sSourceFile)

else

xlWorkbook=xlApp.workbooks.add

end if

 

'判断是否打开一个new file

if bFileExist then    

xlWorkbook.save

else

xlWorkbook.saveas sSourceFile

end if

原创粉丝点击