Automation error when deleting worksheet

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
I am using the code shown.
My goal is to not see the confirmation message when deleting.
The below code deletes the worksheet without the confirmation message BUT the shows me an Automation Error

If i remove the False & True lines the sheet is deleted but confirmation message is shown.

Rich (BB code):
Private Sub DeleteWorksheet_Click()
  Application.DisplayAlerts = False
  ActiveSheet.Delete  ' THIS WILL DELETE THE GENERATED WORKSHEET THEN ONCE DELETED RETURN TO WORKSHEET INV
  Application.DisplayAlerts = True
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I am assuming that it is because the code is deleting the worksheet that the code itself is stored in.

Try changing that worksheet module code to

VBA Code:
Private Sub DeleteWorksheet_Click()
  Remove_Sht
End Sub

and put this code in a standard module, not the worksheet module.

VBA Code:
Sub Remove_Sht()
  Application.DisplayAlerts = False
  ActiveSheet.Delete
  Application.DisplayAlerts = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,133
Messages
6,123,235
Members
449,092
Latest member
SCleaveland

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top