ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   OnKey Method (https://www.excelbanter.com/excel-programming/337826-onkey-method.html)

Tha BeatMaker[_12_]

OnKey Method
 

I need help with the onkey method. I can not get it to work.

I have created a userform, label and macro named UserForm1, lblPress
and Functest respectively. Here is my code. What am I doing wrong?

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=39749


Gary's Student

OnKey Method
 
Its hard to advise here, but:

1. make sure your stuff is in the ThisWorkbook module
2. you might need private sub workbook_open() to do the initialization
--
Gary's Student


"Tha BeatMaker" wrote:


I need help with the onkey method. I can not get it to work.

I have created a userform, label and macro named UserForm1, lblPress,
and Functest respectively. Here is my code. What am I doing wrong?

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 Sub


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




All times are GMT +1. The time now is 04:19 PM.

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