+ Reply to Thread
Results 1 to 7 of 7

Q. Shortcut key to execute an event procedure

  1. #1
    Registered User
    Join Date
    04-04-2007
    Posts
    1

    Q. Shortcut key to execute an event procedure

    I have a command button on my worksheet.
    When it is clicked an event procedure executes.

    Q1) How do I assign a keyboard shortcut to this button so I don't have to click it?

    I have solved this by making the Private Sub CommandButton1_Click into Static so it appears in the standard macro list and then I assign a shortcut

    - but is this the correct way to do it, are there any better/easier ways ?



    Q2) How do I assign the shortcut CTRL F1 to the button ?

    When the sheet it is finished it will be protected and users will not need access to Format Cells. I cannot seem to get assign CTRL+F1 to a macro (or any function key for that matter) - is it possible?


    Any help appreciated folks!

  2. #2
    Registered User
    Join Date
    01-21-2004
    Location
    Liverpool
    MS-Off Ver
    2003
    Posts
    88
    simple answer no its not possible.

    Think only way to assign the shortcut key is how you are doing
    regards
    Paul
    http://www.frontlineuk.com
    FrontLineUK

  3. #3
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon jno

    You could perhaps use a workaround like this :

    Sub test()
    Application.OnKey "^{F1}", "MyMacro"
    End Sub

    Once run, whenever Ctrl + F1 is pressed, the macro "MyMacro" will be run.

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    dominicb

    Please follow the forum rules & wrap your vba code

    see red link below
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  5. #5
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Not sure how you'd get this option to work with CTRL+F1, but you could also just amend your command button's properties to include an Accelerator key.

    In design mode, right-click on your button and choose Properties. In the accelerator field, type one of the letters in your command button's caption (e.g. if your command button caption is "My Button", type the letter M into the Accelerator field.

    Close the properties window and take the sheet out of design mode. Now your M should have an underline beneath it. If you press ALT + M, it will activate that button.

    If you're bent on using CTRL+F1, dominic's code should suffice.

  6. #6
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Mudraker

    Unfortunately, my computer at work doesn't recognise all buttons on websites, and this extends to the buttons to wrap code, format text, quote text etc, so if I answer a question at work any code is going to be unwrapped.

    DominicB

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Dom,
    1) if you want you can type {left square bracket}CODE{right square bracket} your code {left square bracket}/CODE{right square bracket} to keep the mods happy. (Its surprizing how long it took me to figure out how to show you that.)


    2) If the routine you wrote is put in the Wookbook Open routine, it will be automaticaly exicuted. The corresponding
    Please Login or Register  to view this content.
    should be in the Workbook_Close

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1