Macro keyboard shortcuts

R

Roger PB

When using Excel's macro recorder to define a macro, one has the option of
giving it
a keyboard shortcut.
This appears in the finished macro as a comment.
But comments are not executed, I thought.

So what and where is the code giving the subroutine a shortcut, and how
would one enter it on the code page directly rather than by using the
macro recorder?

Roger PB
 
B

Bob Phillips

Roger,

That is just a comment to let you know that the macro is using a shortcut,
it doesn't actually do anything about the shortcut. Delete the comments and
the shortcut still works.

Shortcut key details are held in Excel memory.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
D

Dave Peterson

If you export the module to a .bas file, then look at that file using notepad,
you can see the shortcut.

You can assign the shortcut after the fact using:
tools|macro|macros|options button

You can assign a shortcut in code, too. Take a look at
application.macrooptions:

Option Explicit
Sub testme()
MsgBox "hi"
End Sub
Sub createshortcut()
Application.MacroOptions macro:=ThisWorkbook.Name & "!testme", _
hasshortcutkey:=True, ShortcutKey:="C"
End Sub

This assigns ctrl-Shift-C to that TestMe msgbox routine
 

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