ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using function keys in macros (https://www.excelbanter.com/excel-programming/337680-using-function-keys-macros.html)

Tha BeatMaker[_10_]

Using function keys in macros
 

Is there a way to let the function keys control a macro? For example, I
want to write a program that will run a macro whenever you press F1.
How would I do that?


--
Tha BeatMaker
------------------------------------------------------------------------
Tha BeatMaker's Profile: http://www.excelforum.com/member.php...o&userid=23998
View this thread: http://www.excelforum.com/showthread...hreadid=397040


Chip Pearson

Using function keys in macros
 
See the OnKey method in help. E.g., to assign a macro to F1, use

Application.OnKey "{F1}", "MacroName"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Tha BeatMaker"

wrote in message
news:Tha.BeatMaker.1tzfuc_1124406334.2583@excelfor um-nospam.com...

Is there a way to let the function keys control a macro? For
example, I
want to write a program that will run a macro whenever you
press F1.
How would I do that?


--
Tha BeatMaker
------------------------------------------------------------------------
Tha BeatMaker's Profile:
http://www.excelforum.com/member.php...o&userid=23998
View this thread:
http://www.excelforum.com/showthread...hreadid=397040




Tha BeatMaker[_11_]

Using function keys in macros
 

I have created a userform, label and macro named UserForm1, lblPress
and Functest respectively. Here is my code.

Private Sub UserForm_Initialize()
Application.OnKey "{F10}", "functest"
End Sub
----------------------------------------------------------------------
Private Sub UserForm_Terminate()
Application.OnKey "{F10}"
End Sub
----------------------------------------------------------------------
Sub functest()
Const conMsg As String = "You have pressed F10"

lblPress.Caption = conMsg

End Su

--
Tha BeatMake
-----------------------------------------------------------------------
Tha BeatMaker's Profile: http://www.excelforum.com/member.php...fo&userid=2399
View this thread: http://www.excelforum.com/showthread.php?threadid=39704



All times are GMT +1. The time now is 12:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com