How to delete a sheet without Alert message

K

kvenku

I use a VBS script to open a excel file and delete the sheets based o
some condition and Save and then close it.

The sampe script is

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True

On Error Resume Next
objExcel.workbooks.open "D:\FIPackageNEW.xls"

For Each ws In objExcel.Worksheets
If not ws.Name = "Sheet1" Then
ws.delete
End If
Next

objExcel.Save
objExcel = Nothing
objExcel.quit


I am getting a message (Data may exists in the sheet(s) selected fo
deletion. To premanently delete the data, press Delete) when i run thi
script. How to avoid this. There should not be any alert message whil
deleting the sheets.
Thanks in advance
__________________
Kalyana Venkatesh
Eagle Consulting
(e-mail address removed)
 
C

colofnature

Put

Application.DisplayAlerts = False

in the macro somewhere before the "ws.delete" line. This will suppres
any messages (Excel will automatically use the default).


Co
 
T

Tom Ogilvy

Just a caution that this will not work (when issued from an automation
client) in some versions of excel - possibly xl2000 and earlier.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top