shortcut keys

  • Thread starter cass calculator
  • 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
 
P

Peter T

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
 
C

cass calculator

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
 
G

Gord Dibben

Type onkey into the help diaolog when in the VBE

All combos are listed with usage instructions and examples


Gord Dibben MS Excel MVP
 
C

cass calculator

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
 
C

cass calculator

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"
 
C

cass calculator

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.
 

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