PDA

View Full Version : donít want the message box when delete a sheet



uktous
03-10-2012, 09:00 AM
Hi,

I use the following code to delete a sheet. However, a message box appears with the following message.

I donít want the message box. How can I do?

Code:
Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Delete

Message on message box:
Data may exist in the sheet(s) selected for deletion. To permanent delete the data, press Delete.

dazwm
03-10-2012, 09:09 AM
Try adding this line of code at the start of your code




Application.DisplayAlerts = False

GTO
03-10-2012, 11:58 AM
Along with dawzwm's suggestion, I would suggest tunring the alerts back on as soon as possible.

Option Explicit

Sub example()
Application.DisplayAlerts = False

ThisWorkbook.Worksheets("Sheet1").Delete

'OR - use the worksheet's CodeName:
shtSheet2.Delete
'Note that in the above, I had changed the sheet's CodeName in the Properties window
'in VBE, from its default of 'Sheet2' to 'shtSheet2'

'I would suggest always turning the warnings back on as soon as possible.
Application.DisplayAlerts = True
End Sub