PDA

View Full Version : [SOLVED] Trigger event when pressing F12



YasserKhalil
10-13-2016, 11:22 PM
Hello everyone

How to trigger an event in worksheet change if F12 is pressed ?
I mean when the user press F12 I need to display a message for him or run specific code
Thanks advanced for help

GTO
10-14-2016, 02:42 AM
Greetings,

In ThisWorkbook Module:


Option Explicit

Private Sub Workbook_Activate()
Application.OnKey "{F12}", "Module1.example"
End Sub

Private Sub Workbook_Deactivate()
Application.OnKey "{F12}"
End Sub


In a Standard Module named Module1:


Option Explicit

Sub example()
MsgBox "I pressed F12!", vbOKOnly Or vbInformation, vbNullString
End Sub



Does that help?

Mark

snb
10-14-2016, 03:52 AM
Why not using a button ?

You'd better not interfere with the standard keyboard layout.

YasserKhalil
10-14-2016, 07:48 AM
@Mr. GTO
Thank you very much for this wonderful solution. That's exactly what I was searching for

@Mr. snb
Thanks for reply. My purpose is to prevent F12 key (Save As Function) and at the same time tell the user it is prohibited ..

Best Regards