Quote:
Originally Posted by Dave Peterson
And if you have multiple workbooks open and go from the Help sheet to a
different workbook, then the worksheet_deactivate event won't fire.
You may want to add Workbook_Activate and Workbook_Deactivate code, too.
Dave Peterson
Hey dave,
I have implemented the code norman had suggested, and it's working for me
although i'm getting the problem you have described
I'll be in an excel file with out any code at all and not linked to the workbook with the delete prevention code
and i'll go to delete a sheet in the file without any code, and my workbook with the code will open and then the message to prevent the deletion will pop up
Are you saying i'd have to add those activate and deactivate commands to any new workbook file i make? a little confused on how to prevent this from happening
obviously i only want this prevent deleting to be in that one particular file and not be applied to anything else
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 = "RefuseToDelete"
Ctrl.State = msoButtonUp
End If
Next
End Sub
Code:
Private 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
The above represents worksheet event code and should be pasted into the Help
sheets's code module (not a standard module and not the workbook's
ThisWorkbook module):
************************************************************
Right-click the Help sheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.
************************************************************
Now paste the following sub into a standard module:
Code:
Public Sub RefuseToDelete()
MsgBox "This help sheet should not be deleted!", _
Buttons:=vbExclamation, _
Title:="Cannot Deelete Help!"
End Sub
Thanks for any help!,
jubi