0

我在 QTP 中有以下代码:

Dim objexcel
Set objexcel = createobject("Excel.application")

objexcel.Visible = True

objexcel.Workbooks.Add
objexcel.Cells(1,1).Value =  "ABCDE"
objexcel.ActiveWorkBook.SaveAs("J:\Test.xls")

如何关闭文件并删除它,我尝试了很多方法,但最终得到对象错误。

提前感谢

4

1 回答 1

1

您需要创建类的对象Filesystemobject来删除任何文件,所以代码应该是这样的

Dim objExcel,objFSO
Set objExcel = createobject("Excel.application")
Set objFSO = CreateObject("Scripting.Filesystemobject")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1,1).Value =  "ABCDE"
objExcel.ActiveWorkBook.SaveAs("J:\Test.xls")
objExcel.Workbooks.Close
objExcel.Quit
set objExcel = nothing
objFSO.DeleteFile("J:\Test.xls")
Set objFSO =  nothing 
于 2013-01-16T04:44:34.777 回答