Is there anyway to prevent certain sheets from be deleted?
i know there is protect workbook, but that prevents the user from deleting any sheet
Is there anyway to prevent certain sheets from be deleted?
i know there is protect workbook, but that prevents the user from deleting any sheet
See if example helps
Code used
In sheet1 module (right click sheet1 rab > select view code)
Private Sub Worksheet_Activate() Dim CB As CommandBar Dim Ctrl As CommandBarControl For Each CB In Application.CommandBars Set Ctrl = CB.FindControl(ID:=847, recursive:=True) If Not Ctrl Is Nothing Then Ctrl.OnAction = "PreventDelete" Ctrl.State = msoButtonUp End If Next End Sub
Code in a normal modulePrivate Sub Worksheet_Deactivate() Dim CB As CommandBar Dim Ctrl As CommandBarControl For Each CB In Application.CommandBars Set Ctrl = CB.FindControl(ID:=847, recursive:=True) If Not Ctrl Is Nothing Then Ctrl.OnAction = "" Next End Sub
VBA NoobPublic Sub PreventDelete() MsgBox "Sorry, Cannot delete this sheet!", _ Buttons:=vbExclamation, _ Title:="Cannot Delete Sheet!" End Sub
Last edited by VBA Noob; 12-19-2007 at 04:14 PM.
_________________________________________
Credo Elvem ipsum etian vivere
_________________________________________
A message for cross posters
Please remember to wrap code.
Forum Rules
Please add to your signature if you found this link helpful. Excel links !!!
awesome, thanks man!
so uh how do i turn it off? lol
i ran it on a sheet i do want to be able to delete and can't figure it out ha
Code is triggered when you select or unselected sheet1. Unselect sheet1 to turn off
VBA Noob
so uh, i tried making a new workbook entirely, and the macro followed it there
for example, lets say i select sheet3, and then right click to try and delete, it pops open the excel with the preventdelete macro and doesn't allow me to do even if i disable macros
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks