Deleting sheets

R

ranswrt

I have a procedure that deletes sheets from the workbook. The problem I have
is Excel has window pop up that asks if I still want to delete the sheet. If
I select cancel the procedure continues to run as if the sheet was deleted.
How do I stop the procedure if delete sheet is canceled or get the window not
to pop up?
Thanks
 
J

Jim Thomlinson

Application.DisplayAlerts = False
Sheets("Sheet 1").Delete
Application.DisplayAlerts = True

The above code should keep the message from appearing. If you let the
message pop up then you need to check if the sheet still exists after the
delete...
 
R

ranswrt

Thanks

Jim Thomlinson said:
Application.DisplayAlerts = False
Sheets("Sheet 1").Delete
Application.DisplayAlerts = True

The above code should keep the message from appearing. If you let the
message pop up then you need to check if the sheet still exists after the
delete...
 
G

Gary Brown

You have to change the macro to something like...

'/--------------------------------------------------------/
varAnswer = MsgBox("Delete worksheet?", vbYesNo)

If varAnswer <> vbYes Then
Exit Sub
End If
'/--------------------------------------------------------/

--
Hope this helps.
If this post was helpfull, please remember to click on the ''''YES''''
button at the bottom of the screen.
Thanks,
Gary Brown
 

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

Similar Threads

Can't delete sheets 8
Lookup VBA 6
clear all sheets code 4
Delete sheet code 1
find sheet 3
Drawn Objects Q 2
Deleting Sheets via Macro 6
Called procedure ignoring "With Sheets" command 2

Top