how to trap the Function Keys ?

Billm

Board Regular
Joined
Mar 19, 2002
Messages
88
Aswell as clicking a button on the spreadsheet, my users want to be able to press one of the Function Keys or a Control-Function Key to achieve the same thing. So I thought of using a Macro that responded to a Function Key but I couldnt get it to run the Sub button_click() code that the button runs.

Is there another way to trap when a user presses F8 or Control-F8 and then call this sub ?
Thanks Bill
 
I am trying to reset the F8 key back to the Excel default, using:
Sub RemoveIt()
Application.OnKey "{F8}", ""
End Sub

But, when I put my worksheet code in Debug mode and press the F8 key to step through the code line by line, nothing happens. Using the Menu item "debug / Step Into" works fine, so it looks to me like the F8 is disabled.

How can I reset it back to the Excel default ?

Thanks Bill
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi Bill,

The code that you used, Application.OnKey "{F8}", "", does disable the F8 key.

Try just Application.OnKey "{F8}"

HTH
 
Upvote 0
Richie
thanks, but that didnt do anything either. I've checked the complete workbook and there are no references at all to onkey that could be re-setting it back when it closes either. The F8 just seems disabled whilst the other F-keys work fine.
Bill
 
Upvote 0
Hi Bill,

I'll have a further look at this but in the meantime I've just noticed that the previous page refers to F9 whereas this page refers to F8. Is that the problem?
 
Upvote 0
Hi Bill,

The following works fine on my computer:

<pre>Sub onkeytest()
Application.OnKey "{F9}", "test1"
End Sub

Sub test1()
MsgBox "hello"
End Sub

Sub onkeyrem()
Application.OnKey "{F9}"
End Sub</pre>

Remember that F9 is the recalculate key. Try going to Tools/Options and setting calculation to manual, then change a figure in a calculation, then press F9 to make it calculate. (Remember to switch back to Automatic again once finished testing!)

HTH
 
Upvote 0
Hi Richie
If I use your 3 routines, exactly as is, then the F9 key pops up that message corrctly, and the last one disables the F9 key.

if I then change both occurances of F9 to F8 and re-run exactly as above, then nothing happens at all. Change it all back to F9 and it works again.

Maybe my F8 key has become disabled within the MS Win2000 o/s ? What I am trying to do is to get the Debug Step-into function working via the F8 key, but seems like the F8 key is deceased ! Any ideas how I can check it out, outside of excel ?
Thanks
Bill
 
Upvote 0
Hi Bill,

Please forgive me if I state the obvious first ... you do have the blinking cursor within a routine when you try to step through with F8 don't you? If its not in a routine, just in space within the module, it won't do anything.

EDIT: Have also just tested above routines with F8 instead of F9. No problems.

_________________<font color="blue"> «««<font color="red">¤<font color="blue"><font size=+1>Richie</font><font color="red">¤<font color="blue"> »»»</font>

caffeine_sample.gif
</gif>
This message was edited by Richie(UK) on 2002-10-14 06:10
 
Upvote 0
Yep, the cursor is blinking within the routine, using menu debug/step-into works fine, but pressing F8 does nothing. Pressing F9 inserts a Bookmark ok too. Baffled !! :((
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,400
Members
449,448
Latest member
Andrew Slatter

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top