PDA

View Full Version : Keyboard shortcuts



tomsweddy
08-07-2009, 02:12 AM
Hi,

I know how to program keyboard shortcuts in Excel using the Macro tool button 'Options' but does anyone know the code you could enter in VBA to run a sub from a keyboard shortcut?

I swear the commented out code i.e. 'Keyboard Shortcut Ctrl+R
wouldnt work?

Tom

mdmackillop
08-07-2009, 02:50 AM
Why would you do this? You just Call the sub you want to run.

Sub Macro1()
Call Macro2
Call Macro3 (Arg)
End Sub

Paul_Hossler
08-07-2009, 12:28 PM
Are you looking for Application.OnKey, which will will allow you to assign a key combanation to a macro from within VBA?


Application.OnKey "%{DELETE}", "MyClearAll"


Paul

Tinbendr
11-24-2009, 08:21 AM
I guess I'm having a senior moment.

I put this
Application.OnKey "^%Q", "TABOVER"in the workbook_open event. Is that correct? Cause it ain't working!

Then in Module1 I have
Sub TabOver()
'Goto Column N
Application.GoTo Reference:=Worksheets("DATA").Range("N" & ActiveCell.Row)
End Sub
Excel 2007

GTO
11-24-2009, 02:47 PM
Hi tinbendr, :hi:

I believe it is "working", leastwise in 2000 - its just not obvious. The 'q' just needs to be in lowercase (I am assuming you're not using shift).

Mark

Tinbendr
11-24-2009, 02:53 PM
But I had CAPS LOCK on! So, you would think it has to be in upper case in the code. WRONG! :doh: It still has to be in lower case.

Thanks!