title: vbsript and excel delete all worksheets except last one
body: <p>I am trying to delete all worksheet in excel exept last one and save it then move its location. I can not get it took work as it deletes all other worksheets but errors out with and out of range error.</p>
  
  <pre><code>Set objExcel = CreateObject("Excel.Application")
  
  objExcel.Visible = True
  objExcel.DisplayAlerts = False
  
  Set objWorkbook = objExcel.Workbooks.Open("C:\M-tek 10-31-12_Tony.xlsx")
  i = objWorkbook.Worksheets.Count
  
  Do while i = i
  i = i - 1
  objWorkbook.Worksheets(i).Delete
  Loop
  </code></pre>