title: How to exit gracefully closing open excel file on error?
body: <p>I use dos .bat file to run a .vbs file continuously ... If any error occurs the batch file runs the vbscript again and it goes on. The script connects via internet to a site to execute some api calls. 
  Now when there is connection problem or any other error then the control comes out of the script keeping the excel file open. This way many excel files gets open on each error ... The code is as follows ... please advice me how to close the excel file on error and then come out of the script gracefully.</p>
  
  <pre><code>       '{{{{Some coding}}}}
  
  dim objExcel, objWorkbook, objRange
  Set objExcel = CreateObject("Excel.Application")
  Set objWorkbook = objExcel.Workbooks.Open("C:\temp.xlsx")
  objExcel.Visible = True
  
         '{{{{Some coding}}}}
  
  objExcel.Cells(xlrow, 3).Value="Test"
  objExcel.Cells(xlrow, 3).Select
  objExcel.Activecell.Show
  
         '{{{{Some coding}}}}
  
  objExcel.Workbooks(1).save
  objExcel.Workbooks(1).close
  objExcel.Quit
  Set objExcel = Nothing
  Set objWorkbook = Nothing
  WScript.Quit
  </code></pre>
  
  <p>Thanks in advance </p>