Results 1 to 1 of 1

Workbooks automatically open macro

Threaded View

longbow007 Workbooks automatically open... 06-16-2010, 08:58 PM
  1. #1
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Workbooks automatically open macro

    Hello, I am using Excel 2003 and I am unable to delete any worksheets contained within any of my workbooks (except my workbook named: 4-3-2-1 Report.xls). When I do, the Excel Security Warning pops-up (Screen-shot attached) and opens up my workbook named: 4-3-2-1 Report.xls. I originally created the 4-3-2-1 Report.xls workbook to prevent the user accidently deleting Sheet1. Strangely, I am able to delete all the other worksheets contained in workbook named: 4-3-2-1 Report.xls (Except: Sheet1). I do not understand why I am unable to delete any worksheets from my other workbooks?? and it seems strange that when I do, the macro contained within the workbook named: 4-3-2-1 Report.xls is autmatically activated.

    I copied the "RefuseToDelete" macro from another forum. It seems to work OK. I have tried deleting the macro and the VBA code for Sheet1 (in workbook named: 4-3-2-1 Report.xls) but it made no difference Everytime I wish to delete a worksheet from another workbook, I keep getting various pop-up messages (usually saying things like: unable to find file or unable to locate the macro "RefuseToDelete" etc...)

    Any suggestions on what I can do please?

    Kind regards,

    Chris


    Sub RefuseToDelete()
    MsgBox "This sheet should not be deleted!", _
    Buttons:=vbExclamation, _
    Title:="Cannot Delete This Sheet!"
    End Sub

    Sheet1 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
    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
    Private Sub ResetDelete()
    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.Reset
    Next CB
    End Sub
    Attached Images Attached Images
    Last edited by longbow007; 06-16-2010 at 09:19 PM.

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