Consulting

Results 1 to 4 of 4

Thread: Trigger event when pressing F12

  1. #1

    Trigger event when pressing F12

    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

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    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

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Why not using a button ?

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

  4. #4
    @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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •