Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default RePost - Calling a Macro from a key

Given I haven't received any response I assume that my original post (quoted below) was
not clear so I'll attempt to re-phrase the question.

How can I execute a macro when the user hits the "+" sign on the numeric keypad?

Original post;

I'd like call a macro (to re-position the cursor) when the "+" sign is pressed on the
numeric keypad.
After looking through the help and "playing around", the closest I can come is using an
"OnKey" statement but I can't get it to;

a) recognize the keypad "+"
b) call a macro, *even* when I give it a key that it can recognize.

ex, using the keyboard "+" sign.

I tried putting the Application.OnKey "{+}", "macroname" in a workbook open event and in
the Workbook module I put the "macroname" sub.
(The close event resets the key.)

What I get is "filename!macroname not found" (at least I know it's re-assigned the key!)

So I have two problems (not to mention my lack of understanding)
1st - I'm not structuring the logic correctly (it can't locate the macro) and,
2nd - I have no idea what the code is for the keypad "+" sign.

Direction?


--
Regards;
Rob
------------------------------------------------------------------------


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default RePost - Calling a Macro from a key

Rob,

" I have no idea what the code is for the keypad "+" sign"

This works for me...
Application.OnKey "{107}", "ColorCell"

Regards,
Jim Cone
San Francisco, USA


"RWN" wrote in message
...
Given I haven't received any response I assume that my original post (quoted below) was
not clear so I'll attempt to re-phrase the question.
How can I execute a macro when the user hits the "+" sign on the numeric keypad?
Original post;
I'd like call a macro (to re-position the cursor) when the "+" sign is pressed on the
numeric keypad.
After looking through the help and "playing around", the closest I can come is using an
"OnKey" statement but I can't get it to;
a) recognize the keypad "+"
b) call a macro, *even* when I give it a key that it can recognize.
ex, using the keyboard "+" sign.
I tried putting the Application.OnKey "{+}", "macroname" in a workbook open event and in
the Workbook module I put the "macroname" sub.
(The close event resets the key.)
What I get is "filename!macroname not found" (at least I know it's re-assigned the key!)
So I have two problems (not to mention my lack of understanding)
1st - I'm not structuring the logic correctly (it can't locate the macro) and,
2nd - I have no idea what the code is for the keypad "+" sign.
Direction?
Regards;
Rob


  #3   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default RePost - Calling a Macro from a key

Jim;
Thanks for that.
Now, if I can test your patience further, I'm stuck on how the call works.

I put the sub (ColorCell) in sheet1.
When I hit "+" I get an error message "The macro 'sheet1!ColorCell' cannot be found"
What am I missing (and I know I'm going to feel stupid!)?

--
Regards;
Rob
------------------------------------------------------------------------
"Jim Cone" wrote in message
...
Rob,

" I have no idea what the code is for the keypad "+" sign"

This works for me...
Application.OnKey "{107}", "ColorCell"

Regards,
Jim Cone
San Francisco, USA


"RWN" wrote in message
...
Given I haven't received any response I assume that my original post (quoted below)

was
not clear so I'll attempt to re-phrase the question.
How can I execute a macro when the user hits the "+" sign on the numeric keypad?
Original post;
I'd like call a macro (to re-position the cursor) when the "+" sign is pressed on the
numeric keypad.
After looking through the help and "playing around", the closest I can come is using

an
"OnKey" statement but I can't get it to;
a) recognize the keypad "+"
b) call a macro, *even* when I give it a key that it can recognize.
ex, using the keyboard "+" sign.
I tried putting the Application.OnKey "{+}", "macroname" in a workbook open event and

in
the Workbook module I put the "macroname" sub.
(The close event resets the key.)
What I get is "filename!macroname not found" (at least I know it's re-assigned the

key!)
So I have two problems (not to mention my lack of understanding)
1st - I'm not structuring the logic correctly (it can't locate the macro) and,
2nd - I have no idea what the code is for the keypad "+" sign.
Direction?
Regards;
Rob




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default RePost - Calling a Macro from a key

Rob,

Did you see Gary Brown's post?
Also, put the code in a regular/general module and try it.

Regards,
Jim Cone


"RWN" wrote in message
...
Jim;
Thanks for that.
Now, if I can test your patience further, I'm stuck on how the call works.

I put the sub (ColorCell) in sheet1.
When I hit "+" I get an error message "The macro 'sheet1!ColorCell' cannot be found"
What am I missing (and I know I'm going to feel stupid!)?

--
Regards;
Rob



------------------------------------------------------------------------
"Jim Cone" wrote in message
...
Rob,

" I have no idea what the code is for the keypad "+" sign"

This works for me...
Application.OnKey "{107}", "ColorCell"

Regards,
Jim Cone
San Francisco, USA


  #5   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default RePost - Calling a Macro from a key

BINGO!!
Put it in a general module and it worked, without any qualification at all.

If I don't re-set the key and close the workbook then it still works on any
workbook/sheet-not that I'd want to do that!
(it opens the book that the macro is in-magic.)

I think the light is coming on, thanks to the two of you!

Now, off to play.

Again, thanks to you both - I'm a better person now.
--
Regards;
Rob
------------------------------------------------------------------------
"Jim Cone" wrote in message
...
Rob,

Did you see Gary Brown's post?
Also, put the code in a regular/general module and try it.

Regards,
Jim Cone


"RWN" wrote in message
...
Jim;
Thanks for that.
Now, if I can test your patience further, I'm stuck on how the call works.

I put the sub (ColorCell) in sheet1.
When I hit "+" I get an error message "The macro 'sheet1!ColorCell' cannot be found"
What am I missing (and I know I'm going to feel stupid!)?

--
Regards;
Rob



------------------------------------------------------------------------
"Jim Cone" wrote in message
...
Rob,

" I have no idea what the code is for the keypad "+" sign"

This works for me...
Application.OnKey "{107}", "ColorCell"

Regards,
Jim Cone
San Francisco, USA






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default RePost - Calling a Macro from a key

I don't believe that you can distinguish between the keyboard and the keypad
PLUS SIGN using OnKey.I do believe that the syntax you are using is correct,
however.You may need to be more specific with your macro.For
example...Instead of Application.OnKey "{+}", "MyMacro"You may have to
sayApplication.OnKey "{+}", "MyWorkbook!MyMacro"HTH,Gary Brown


  #7   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default RePost - Calling a Macro from a key

Thanks Gary;
Jim Cone gave me the key code (107) - and that works.

I've posted back to him that I cannot get the macro to execute however.

Your post gave me the idea that I should be qualifying the macro name, so I used;

Application.OnKey "{107}", "TestIT!ColorCell"

Now get the error message - The macro "C:\dirname\[TestKeyCall.xls]TestIt'!ColorCell'
cannot be found

(I didn't expect the "!" to appear inside the single quote though??)

In the TestIt sheet I have;

Sub ColorCell()
Beep
End Sub


--
Regards;
Rob
------------------------------------------------------------------------
"Gary Brown" wrote in message
...
I don't believe that you can distinguish between the keyboard and the keypad
PLUS SIGN using OnKey.I do believe that the syntax you are using is correct,
however.You may need to be more specific with your macro.For
example...Instead of Application.OnKey "{+}", "MyMacro"You may have to
sayApplication.OnKey "{+}", "MyWorkbook!MyMacro"HTH,Gary Brown




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 167
Default RePost - Calling a Macro from a key

Rob,

Not sure if you still need an answer to this problem. I was trying to do
something similar, followed the help you received here, and receive the same
error.

The problem (at least for me) was that I was trying to call a function by
pressing a key. As far as I know this isn't possible. However, if you
record a macro then replace the macro (module) code with the code you want
executed then it works.

For instance, my call was Application.OnKey "~","NextEntry"
I recorded a macro named NextEntry. Then I edited the macro in VBA and
replaced the macro code I had recorded with the code I wanted to be executed.

Hope this helps you or someone else.

Mike

"RWN" wrote:

Thanks Gary;
Jim Cone gave me the key code (107) - and that works.

I've posted back to him that I cannot get the macro to execute however.

Your post gave me the idea that I should be qualifying the macro name, so I used;

Application.OnKey "{107}", "TestIT!ColorCell"

Now get the error message - The macro "C:\dirname\[TestKeyCall.xls]TestIt'!ColorCell'
cannot be found

(I didn't expect the "!" to appear inside the single quote though??)

In the TestIt sheet I have;

Sub ColorCell()
Beep
End Sub


--
Regards;
Rob
------------------------------------------------------------------------
"Gary Brown" wrote in message
...
I don't believe that you can distinguish between the keyboard and the keypad
PLUS SIGN using OnKey.I do believe that the syntax you are using is correct,
however.You may need to be more specific with your macro.For
example...Instead of Application.OnKey "{+}", "MyMacro"You may have to
sayApplication.OnKey "{+}", "MyWorkbook!MyMacro"HTH,Gary Brown





  #9   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default RePost - Calling a Macro from a key

Mike;
Thanks for the reply.
Actually got it working using the following code in the Workbook module.

Private Sub Workbook_Open() 'Set "+" numeric kpd to call macro to allow
Application.OnKey "{107}", "DownHome" 'moving cursor to next line,col1 on entry
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnKey "{107}", ""
End Sub

The "DownHome" macro is in a general code module that handles an order entry process.

Sub DownHome()
Set Asht = ActiveSheet
If Asht.Name = "OrderEntry" Then 'Ensure that this is the order entry sheet
and,
Cells(ActiveCell.Row + 1, 1).Select 'if so, go down one line and home to Col A
End If
End Sub

This was done as an entry aid so that the user doesn't have to leave the numeric keypad to
get to the next line.
She enters the phone #, product # etc. and the numeric "+" to shift to the next order.

Again, thanks for the interest.

--
Regards;
Rob
------------------------------------------------------------------------
"crazybass2" wrote in message
...
Rob,

Not sure if you still need an answer to this problem. I was trying to do
something similar, followed the help you received here, and receive the same
error.

The problem (at least for me) was that I was trying to call a function by
pressing a key. As far as I know this isn't possible. However, if you
record a macro then replace the macro (module) code with the code you want
executed then it works.

For instance, my call was Application.OnKey "~","NextEntry"
I recorded a macro named NextEntry. Then I edited the macro in VBA and
replaced the macro code I had recorded with the code I wanted to be executed.

Hope this helps you or someone else.

Mike

"RWN" wrote:

Thanks Gary;
Jim Cone gave me the key code (107) - and that works.

I've posted back to him that I cannot get the macro to execute however.

Your post gave me the idea that I should be qualifying the macro name, so I used;

Application.OnKey "{107}", "TestIT!ColorCell"

Now get the error message - The macro "C:\dirname\[TestKeyCall.xls]TestIt'!ColorCell'
cannot be found

(I didn't expect the "!" to appear inside the single quote though??)

In the TestIt sheet I have;

Sub ColorCell()
Beep
End Sub


--
Regards;
Rob
------------------------------------------------------------------------
"Gary Brown" wrote in message
...
I don't believe that you can distinguish between the keyboard and the keypad
PLUS SIGN using OnKey.I do believe that the syntax you are using is correct,
however.You may need to be more specific with your macro.For
example...Instead of Application.OnKey "{+}", "MyMacro"You may have to
sayApplication.OnKey "{+}", "MyWorkbook!MyMacro"HTH,Gary Brown







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to delete lines based on a value - Repost MarkT Excel Discussion (Misc queries) 2 October 19th 06 03:43 PM
Calling a macro from a key RWN Excel Programming 0 February 8th 05 05:19 AM
Calling Macro by different TextBoxes Jarek[_24_] Excel Programming 0 October 12th 04 06:54 AM
Macro to Delete - repost Dan Excel Programming 0 September 18th 04 12:57 AM
Calling macro in add-in. Clark B Excel Programming 1 July 24th 03 11:05 PM


All times are GMT +1. The time now is 07:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"