ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   On Close Macro - stop warning message (https://www.excelbanter.com/excel-programming/312245-close-macro-stop-warning-message.html)

M Shannon

On Close Macro - stop warning message
 
I have this macro on close:

Sheets("Bakery").Select
ActiveWindow.SelectedSheets.Delete

I need to do two things.

1) If the sheet doesn't exist I want the macro to do
nothing and carry on to delete the next worksheet.

2) If the sheet does exist I want the macro to delete it
without the warning.

Any help is much appreciated.
Many thanks


Dave Peterson[_3_]

On Close Macro - stop warning message
 
You can avoid the error by:

on error resume next
sheets("bakery").delete
on error goto 0

(But what does Next mean if that worksheet doesn't exist?)

And to hide the warning message:

application.displayalerts = false
on error resume next
sheets("bakery").delete
on error goto 0
application.displayalerts = true

and you can delete as many sheets as you want in that little bit of code:

application.displayalerts = false
on error resume next
sheets("bakery").delete
sheets("butcher").delete
sheets("candlestickmaker").delete
on error goto 0
application.displayalerts = true



M Shannon wrote:

I have this macro on close:

Sheets("Bakery").Select
ActiveWindow.SelectedSheets.Delete

I need to do two things.

1) If the sheet doesn't exist I want the macro to do
nothing and carry on to delete the next worksheet.

2) If the sheet does exist I want the macro to delete it
without the warning.

Any help is much appreciated.
Many thanks


--

Dave Peterson


Tom Ogilvy

On Close Macro - stop warning message
 
On Error Resume Next
Application.Displayalerts = False
Sheets("Bakery").Delete
Applicaton.displayAlerts = True
On Error goto 0

--
Regards,
Tom Ogilvy



"M Shannon" wrote in message
...
I have this macro on close:

Sheets("Bakery").Select
ActiveWindow.SelectedSheets.Delete

I need to do two things.

1) If the sheet doesn't exist I want the macro to do
nothing and carry on to delete the next worksheet.

2) If the sheet does exist I want the macro to delete it
without the warning.

Any help is much appreciated.
Many thanks





All times are GMT +1. The time now is 09:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com