ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   code to prevent users from adding new worksheets (https://www.excelbanter.com/excel-worksheet-functions/224822-code-prevent-users-adding-new-worksheets.html)

jat

code to prevent users from adding new worksheets
 
i want to prevent users from adding new or blank worksheets on a form, but i
cannot get the code below to work:

Private Sub Workbook_NewSheet(ByVal Sh As Object)
If Not BlockInsertSheet Then Exit Sub
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
Sh.Delete
With Application
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub


i have te code in the Microsoft Excel Objects, This Workbook module but i
cannot get it to work. what's missing?

jat


Mike H

code to prevent users from adding new worksheets
 
Hi,

Try this. Double click 'ThisWorkbook' and paste this in on the right

Private Sub Workbook_NewSheet(ByVal Sh As Object)
Application.DisplayAlerts = False
MsgBox "No new sheets thank you"
Sh.Delete
Application.DisplayAlerts = True
End Sub


Mike

"jat" wrote:

i want to prevent users from adding new or blank worksheets on a form, but i
cannot get the code below to work:

Private Sub Workbook_NewSheet(ByVal Sh As Object)
If Not BlockInsertSheet Then Exit Sub
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
Sh.Delete
With Application
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub


i have te code in the Microsoft Excel Objects, This Workbook module but i
cannot get it to work. what's missing?

jat


Alan

code to prevent users from adding new worksheets
 
You can do that by password protecting the workbook,
Regards,
Alan.
"jat" wrote in message
...
i want to prevent users from adding new or blank worksheets on a form, but
i
cannot get the code below to work:

Private Sub Workbook_NewSheet(ByVal Sh As Object)
If Not BlockInsertSheet Then Exit Sub
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
Sh.Delete
With Application
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub


i have te code in the Microsoft Excel Objects, This Workbook module but i
cannot get it to work. what's missing?

jat




All times are GMT +1. The time now is 02:38 AM.

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