User assigned keyboard shortcuts (ALT) not working

Dr. Demento

Well-known Member
Joined
Nov 2, 2010
Messages
559
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
 

Some videos you may like

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,977
Office Version
  1. 2016
Platform
  1. Windows
@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:

Dr. Demento

Well-known Member
Joined
Nov 2, 2010
Messages
559
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,113,825
Messages
5,544,545
Members
410,619
Latest member
gregor222
Top