shortcut keys

  • Thread starter Thread starter cass calculator
  • Start date Start date
C

cass calculator

How do you assign a macro to a shortcut key other than a combination
of ctrl that excel allows you to do from the tools>macro>options
screen? For example, what if i want to use Alt + 1, or Shift + Ctrl +
1, or Alt + Shift + 1?

Thanks!

J
 
You can assign Shift+Ctrl+letter manually the same way as Ctrl+letter. It's
simply the same but with the capital. You can also use
Application.MacroOptions, see help. (can also export the bas module to text
file, add the shortcut, and re-import).

If you want to include Alt + letter w/out any combination of Shift+Ctrl you
need to use the OnKey method, again see help for example. You will need to
run the OnKey code each time your macro project loads.

Regards,
Peter T
 
OnKey allows many more key combinations

Could you please show me a simple example for how to use the OnKey
method for combinations of ctrl, shift and alt?

Thanks,

Joshua
 
Type onkey into the help diaolog when in the VBE

All combos are listed with usage instructions and examples


Gord Dibben MS Excel MVP
 
Type onkey into the help diaolog when in the VBE

All combos are listed with usage instructions and examples

Gord Dibben  MS Excel MVP

Sorry guys, I am a novice at this. Do I put the code application.onkey
(key, procedure) into the respective subroutine that I am assigning it
to, or can I put all my onkey code together (i.e. not as a line of a
subroutine)

Joshua
 
Type onkey into the help diaolog when in the VBE

All combos are listed with usage instructions and examples

Gord Dibben  MS Excel MVP

As an example, I have the following code that highlights all the
precedents of a selection, and I'd like to assign it to the shortcut
Ctrl + Shift + J

Sub HighlightPrecedents()
Dim rngCell As Range
For Each rngCell In Selection
rngCell.ShowPrecedents
Next rngCell
End Sub

Where do I put the following code?

Application.OnKey "^+{J}, "HighlightPrecedents"
 
As an example, I have the following code that highlights all the
precedents of a selection, and I'd like to assign it to the shortcut
Ctrl + Shift + J

Sub HighlightPrecedents()
   Dim rngCell As Range
   For Each rngCell In Selection
       rngCell.ShowPrecedents
   Next rngCell
End Sub

Where do I put the following code?

Application.OnKey "^+{J}, "HighlightPrecedents"

I tried it inside the procedure and got the following error - the
macro 'highlightprecedents()' cannot be found. Can someone help!
thanks.
 
Back
Top