How to assign keyboard shortcut to existing Commandbar controls

S

superjas

Hi,

I wish to assign a keyboard shortcut (eg CTRL + SHIFT + D) to the command
control id 398, which changes the formatting of a cell to show another
decimal place.

Could you please show me how it's done?

Many thanks in advance!
 
N

Norman Jones

Hi Superjas,

Copy the following macro into a standard module in your Personal.xls
workbook.

'=============>>
Public Sub IncreaseDecimals()
Application.CommandBars("Formatting"). _
FindControl(ID:=398).Execute
End Sub
'<<=============

Then, either assign the shortcut key combination to the macro manually or
try:

'=============>>
Public Sub Tester()
Const WbName As String = "Personal.xls" '<<==== CHANGE
Application.MacroOptions Macro:=WbName & "!IncreaseDecimals", _
Description:="", ShortcutKey:="D"
End Sub
'<<=============
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top