Giving Back - to Sumit Bansal - Trump Excel



In this one, Sumit prays to the Excel Gods for CTRL \ (backslash) to do what it does in Google Sheets - namely, clear formats.

I'm surprised the MVP doesn't know how to make it happen. (NOTE : click in below code to select)

Easy. Use them PERSONAL.XLSB mate.

In the "ThisWorkbook" Excel Object of your PERSONAL Macro Workbook in the Microsoft VB for Applications Editor (ALT + F11 to launch), just put in

Option Explicit

Private Sub Workbook_Open()
    Application.OnKey "^\", "PERSONAL.XLSB!ClearFormats" 'CTRL backslash
End Sub

Along with 

Sub ClearFormats()
    Selection.ClearFormats
End Sub

In any "Module" in the Module section

And you're in business! Try it!

Untried : 

chatGPT says you can use this macro to list all assigned shortcuts in Excel.. let me k (didn't work :( ) Told chatJi that, but all I got was something longer and just as useless:

Sub ListShortcuts()
    Dim kb As CommandBar
    Dim ctrl As CommandBarControl
    
    For Each kb In Application.CommandBars
        For Each ctrl In kb.Controls
            If ctrl.OnAction <> "" Then
                Debug.Print "Shortcut: " & ctrl.Caption & " - Macro: " & ctrl.OnAction
            End If
        Next ctrl
    Next kb
End Sub

Comments

Popular Posts