0

I have a following code in 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")

How do I close the file and delete it, I tried many ways but I am ending up getting object error.

Thanks in advence

Uska
  • 65
  • 1
  • 6
  • 14

1 Answers1

1

You need to create object of class Filesystemobject to delete any file, so code should be like this

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 
Amol Chavan
  • 3,835
  • 1
  • 21
  • 32