+ Reply to Thread
Results 1 to 5 of 5

Prevent Delete Worksheet Problem

  1. #1
    Forum Contributor bentleybob's Avatar
    Join Date
    02-27-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    644

    Prevent Delete Worksheet Problem

    An old post provided the following macros that purportedly prevent users from deleting a worksheet. Unfortunately, it also makes it so you can't delete ANY worksheet in ANY file, which is of course not what was intended. Can anybody help me figure a way to remove this nuisance? All attempts to delete a sheet keep looking back to the offending workbook, even though the macro has since been deleted from it.

    Thanks.


    Here's what was posted:
    _____________________
    Try pasting the following two event procedures into the Help sheet module:

    '==========================>>
    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
    '-----------------------------------

    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:

    '==========================>>
    Public Sub RefuseToDelete()
    MsgBox "This help sheet should not be deleted!", _
    Buttons:=vbExclamation, _
    Title:="Cannot Delete Help!"

    End Sub
    Last edited by bentleybob; 08-07-2009 at 11:20 AM.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Prevent Delete Worksheet Problem

    You could try running a reset on it:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Contributor bentleybob's Avatar
    Join Date
    02-27-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    644

    Re: Prevent Delete Worksheet Problem

    Nope, that doesn't work.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Prevent Delete Worksheet Problem

    Sorry - typo in there. Run this:
    Please Login or Register  to view this content.
    and remove all the worksheet activate event codes from your workbook.

  5. #5
    Forum Contributor bentleybob's Avatar
    Join Date
    02-27-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    644

    Re: Prevent Delete Worksheet Problem

    Sorry, YES that did work. THANKS!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1