vbsript and excel delete all worksheets except last one
Posted
by
matthew moore
on Stack Overflow
See other posts from Stack Overflow
or by matthew moore
Published on 2012-12-14T17:01:41Z
Indexed on
2012/12/14
17:03 UTC
Read the original article
Hit count: 190
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.
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
© Stack Overflow or respective owner