Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catch a keystroke

Status
Not open for further replies.

Tronsliver

Technical User
Sep 19, 2000
120
US
I have a spreadsheet (sheet 1) and would like to be able to capture the "F1" key when pressed. The intent is to reprogram the key. Can someone give me an example of some sample code. Just a quick example showing how to capture is all I need.

Thank You
 
As in:

application.onkey "{F1}","HelpMe"

I guess you could restrict this to just one worksheet by adding the appropriate worksheet open and close event handlers.
Rob
 
Rob,

Not much info in the help file on this. Would I enter this code in a "procedure"? And where would the procedure/sub be located to get focus when I hit the F1 key?

Thanks
 
You should locate the code in the WorkBook_Open event or in a macro called Sub Auto_Open in a general module. This will ensure that when the workbook is opened, the F1 will trigger whatever code you assigned to it.

Sub Auto_Open
Application.OnKey "{F1}", "MacroName"
End Sub.

If it is possible that you will have other workbooks open at the same time, and would require the normal Help function of the F1 key, you might need to look at the WindowActivate and WindowDeactivate events to turn it on and of fas appropriate.

Application.OnKey "{F1}",""

resets the F1 key to it's default.

A.C.
 
The way I would like to use this is when I'm in sheet1 and hit the F1 key it will do the program I assign to it. I belive I have to associate it with "keypress" somehow?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top