Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using macro in excel, can I delete a worksheet w/out the "click OK" 1

Status
Not open for further replies.

RyanScharfy

Technical User
Jun 17, 2003
86
US
I want the worksheet to be deleted without the annoying "This sheet will be Permanently Deleted", click OK message.

Here's the current code.

Sub DeleteMacro2
Sheets("Macro (2)").Select
ActiveWindow.SelectedSheets.Delete
End Sub
 
Ryan

This is how you do it you need to turn them back on after you delete the sheet or you won't get any alerts



Sub DeleteMacro2
Sheets("Macro (2)").Select
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = true
End Sub


Shrek
 
First, the sheet doesn't need to be selected to delete it:

Code:
Sheets("Macro (2)").Delete

works just as well! ;-)

Check out SkipVought's faq707-4105 How Can I Make My Code Run Faster?

Second, since the .DisplayAlerts and the .ScreenUpdating are Applicaiton functions, I find that it makes it a lot easier to create a Procedure that toggles these functions whenever I need them instead of having to write them everytime.
Code:
Sub NoAlerts()
With Application
    .ScreenUpdating = Not .ScreenUpdating
    .DisplayAlerts = Not .DisplayAlerts
End With
End Sub

Then you can just write your macro like this:
Code:
Sub DeleteMacro2
NoAlerts
Sheets("Macro (2)").Delete
No Alerts
End Sub

Check out the FAQ's in all of the Forums you visit to find out things that can help you! ;-)




Peace! [peace]

Mike

Didn't get the answers that you wanted? Take a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top