Worksheet_Activate macro not consistent across users

mike.magill

New Member
Joined
Jun 24, 2009
Messages
22
I have the following code in the Worksheet_Activate event. The part that should allow a user to activate the InsertRow and DeleteRow macros when right clicking on the row header does not work for some users.

Can anyone identify anything in the code which might not work across all Excel 2010 configurations?

Code:
Sub Worksheet_Activate()
' This macro changes the menu bar and contextual menus for Cells, Rows and Columns to limit
' and control the user's ability to interact with the spreadsheet.
            
    Call Set_Public_Variables
    
    Dim MenuBar As Object
    Dim ColumnBar As Object
    Dim ColumnBar2 As Object
    Dim CellBar As Object
    Dim CellBar2 As Object
    Dim RowBar As Object
    Dim RowBar2 As Object
    Dim cItem As Object
    Dim NewMenu As Object
    Dim MenuItem As Object


    If Right(ThisWorkbook.Name, 5) = ".xltm" Then Exit Sub
    
    Set CellBar = Application.CommandBars("Cell")
    Set CellBar2 = Application.CommandBars(Application.CommandBars("Cell").Index + 3)
    Set RowBar = Application.CommandBars("Row")
    Set RowBar2 = Application.CommandBars(Application.CommandBars("Row").Index + 3)
    Set ColumnBar = Application.CommandBars("Column")
    Set ColumnBar2 = Application.CommandBars(Application.CommandBars("Column").Index + 3)


    CellBar.Reset
    CellBar2.Reset
    RowBar.Reset
    RowBar2.Reset
    ColumnBar.Reset
    ColumnBar2.Reset


    CellBar.Enabled = True
    CellBar2.Enabled = True
    RowBar.Enabled = True
    RowBar2.Enabled = True
    ColumnBar.Enabled = False
    ColumnBar2.Enabled = False


    Call ResizeComments


    ' Restricts items on Cell Contextual Menu to Copy, Paste, Paste Special and Clear Contents
    For Each cItem In CellBar.Controls
        Select Case cItem.Caption
            Case "&Copy", "&Paste", "Paste &Special...", "Clear Co&ntents", "Insert Co&mment"
            Case Else
                cItem.Delete
        End Select
    Next cItem


    ' Restricts items on Cell Contextual Menu to Copy, Paste, Paste Special and Clear Contents
    For Each cItem In CellBar2.Controls
        Select Case cItem.Caption
            Case "&Copy", "&Paste", "Paste &Special...", "Clear Co&ntents", "Insert Co&mment"
            Case Else
                cItem.Delete
        End Select
    Next cItem


    ' If the document is being used as a single risk register....
    If Range("Consol_Marker").Value <> "Consolidation" Then
        
        ' Delete or disable all items on Row Contextual Menu
        For Each cItem In RowBar.Controls
            Select Case cItem.Caption
                Case "Cu&t", "&Copy", "&Paste", "Paste &Special...", "Clear Co&ntents", _
                     "&Format Cells...", "&Row Height", "&Hide", "&Unhide"
                    cItem.Enabled = False
                Case Else
                    cItem.Delete
            End Select
        Next cItem


        ' Delete or disable all items on Row Contextual Menu
        For Each cItem In RowBar2.Controls
            Select Case cItem.Caption
                Case "Cu&t", "&Copy", "&Paste", "Paste &Special...", "Clear Co&ntents", _
                     "&Format Cells...", "&Row Height", "&Hide", "&Unhide"
                    cItem.Enabled = False
                Case Else
                    cItem.Delete
            End Select
        Next cItem


        ' If the autofilter is not enabled add Insert Row and Delete Row macros
        If Worksheets("Risk Register").FilterMode = False Then
            With RowBar.Controls
                With .Add
                   .Caption = "&Insert"
                   .OnAction = "InsertRow"
                   .BeginGroup = True
                   .Move Before:=5
                End With
    
                With .Add
                   .Caption = "&Delete"
                   .OnAction = "DeleteRow"
                   .Move Before:=6
                End With
            End With
        End If
    Else
    
        ' If the document is being used to consolidate....
        ' Delete or disable all items on Row Contextual Menu
        For Each cItem In RowBar.Controls
            Select Case cItem.Caption
                Case "Cu&t", "&Copy", "&Paste", "Paste &Special...", "Clear Co&ntents", _
                     "&Format Cells...", "&Row Height", "&Hide", "&Unhide"
                    cItem.Enabled = False
                Case Else
            End Select
        Next cItem
    
        For Each cItem In RowBar2.Controls
            Select Case cItem.Caption
                Case "Cu&t", "&Copy", "&Paste", "Paste &Special...", "Clear Co&ntents", _
                     "&Format Cells...", "&Row Height", "&Hide", "&Unhide"
                    cItem.Enabled = False
                Case Else
            End Select
        Next cItem
    
    End If


    ' Reroute shortcut keys to relevant macros
    Application.OnKey "{F7}", "Spell_Check"
    Application.OnKey "^p", "Print_Options"
    Application.OnKey "^P", "Print_Options"
    Application.OnKey "^X", ""
    Application.OnKey "^x", ""


    'Disable Print and Print Preview buttons on standard menu bar
    Application.CommandBars("Standard").Controls(6).Enabled = False
    Application.CommandBars("Standard").Controls(7).Enabled = False
    Application.CommandBars("Standard").Controls(10).Enabled = False


End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
are they all set up to have macros run automatically
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,384
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top