View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Call Macro on KeyPress

Hi bw -

"To assign a procedure to one of the special characters (+, ^, %, and so
on), enclose the character in braces." - excerpt from the builtin Visual
Basic Help system.

Using the "+" key to call a procedure is gutsy because it's such a popular
key in and of itself... However, the following code will assign your
procedure to the "+" key in the alphanumeric section of your keyboard; the
"+" key in the numberpad section will function as normal.
-------------------------------------------------------
To have the "+" key fire your procedure in all worksheets, copy the
following code to the ThisWorkbook module. Turning off the assignment in
the Deactivate event will ensure that the "+" key is reset to its normal
function in other workbooks.

"To assign a procedure to one of the special characters (+, ^, %, and so
on), enclose the character in braces." - from the builtin Visual Basic Help
system

Private Sub Workbook_Open()
Application.OnKey "{+}", "yourProcedureHere"
End Sub

Private Sub Workbook_Deactivate()
Application.OnKey "{+}"
End Sub
-------------------------------------------------------

To have the "+" key fire your procedure in one worksheet, copy the following
code to the worksheet's module:

Private Sub Worksheet_Activate()
Application.OnKey "{+}", "yourProcedureHere"
End Sub

Private Sub Worksheet_Deactivate()
Application.OnKey "{+}"
End Sub

--
Jay


"bw" wrote:

If I press the "+" key, I want to call a macro.
I've looked at the OnKey Method, but it doesn't seem to handle my
situation.
How is this done?