Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50057

Disabling Autofilter menu Sort Ascending/Descending commands

$
0
0
Hello dear Excel Experts!

I want to restrict access to the sort features in Excel to select users.

I already implemented some RibbonX repurposing via CustomUI14.xml/CustomUI.xml like so:

Code:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">       

<commands>

        <!-- Intercept Sorting -->
        <command idMso="SortAscendingExcel" onAction="ControlOverride"/>
        <command idMso="SortDescendingExcel" onAction="ControlOverride" />
        <command idMso="SortCustomExcel" onAction="ControlOverride" />
        <command idMso="SortDialog" onAction="ControlOverride" />
        <command idMso="SortDialogClassic" onAction="ControlOverride" />

</commands>

</customUI>

Plus the following macro:

Code:

Sub ControlOverride(control As IRibbonControl, ByRef cancelDefault)

If isAdmin() Then
    Dim iReply As Integer
    iReply = MsgBox(Prompt:="Do you REALLY wish to sort?", Buttons:=vbYesNo)
    If iReply = vbYes Then
        cancelDefault = False
    Else
        cancelDefault = True
        Exit Sub
    End If
Else
    cancelDefault = True
    MsgBox "You are not allowed to sort the spreadsheet!"
End If

End Sub

HOWEVER, I found that this doesn't disable the most important culprit for accidental sorting, the menu item when you click on the little AutoFilter selection boxes:

http://i.imgur.com/4hbE8.png

Does anybody know how to repurpose/intercept these two? They don't seem to be handled via RibbonX...

P.S. Yes, I know that I could also protect the sheet and just enable all features (or most features) apart from sorting but the constant protection/unprotection that would need to be performed is really clunky and impossible on shared workbooks.

Viewing all articles
Browse latest Browse all 50057

Trending Articles