User assigned keyboard shortcuts (ALT) not working

Dr. Demento

Well-known Member
Joined
Nov 2, 2010
Messages
618
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I am having issues getting keyboard shortcuts with ALT to work and I'm wondering if I'm doing something wrong. The CTRL+SHIFT shortcuts work fine; however, in order to minimize re-assigning native CTRL shortcuts that I normally use, I've moved on to using ALT. However, they don't function at all - no error message, nothing.

The code below is in a normal module and is called from the ThisWorkbook on opening. All the CTRL+SHIFT shortcuts work fine but ALT+SHIFT and ALT+CTRL do not. For the ALT+SHIFT, Excel attempts to use it's native ALT shortcut; I get no response of any kind for ALT+CTRL.

Thanks y'all.

Code:
Sub assign_ShortcutKeys()
' ~~ Assign shortcut keys programmatically
' http://vbadud.blogspot.com/2007/06/assigning-shortcut-keys-excel-macros.html
' http://www.contextures.com/excelvbasendkeys.html#keycombo

' ~~ Two alternatives to assign shortcuts
' http://codevba.com/excel/Application.htm#OnKey vs http://codevba.com/excel/Application.htm#MacroOptions

' ~~ Alt key = Percentage (%) symbol _
     Ctrl key = Caret (^) symbol _
     Shift key = Plus (+) symbol

' ~~ Disable Save (Ctrl str): Application.OnKey "^s", ""


'  application.OnKey "^{F12}", "show_ShortCuts"            ' ~~ Show Msgbox with all assigned shortcuts
  Application.OnKey "%^D", "styles_delete"                ' ~~ Delete all custom styles in WorkBook
  Application.OnKey "^+D", "del_blankCells"               ' ~~ Delete blank cells within user selected range
  Application.OnKey "^+F", "run_format_byHeader_arr"      ' ~~ Format data
  Application.OnKey "^+H", "Format_HeaderFooter_ACTIVE"   ' ~~ Header/Footer update
  Application.OnKey "%+L", "rng_toList"                   ' ~~ Transform a range with blanks and/or multiple columns into a single column list

End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
@Dr. Demento

I think the Alt key activates the ribbon menus and that seems to interfere with Application.OnKey

The only workaround I can think of is using an API workaround but it will involve running a continous loop which will have an impact on performance.

If tha's not an issue I can post an example.
 
Last edited:
Upvote 0
Jaafar,

I understand. Thank you for the info. Not keen on degrading performance, so I guess I'll have to get creative in other ways.

Cheers.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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