我在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")
如何关闭文件并将其删除,我尝试了很多方法,但最终我遇到了对象错误。
感谢advence
答案 0 :(得分: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