New Excel Forum

This forum has been moved to TeachExcel.com

Ask all future questions in the New Excel Forum.

ExcelKey

Function keys appear to have to levels?

Macros, VBA, Excel Automation, etc.

Function keys appear to have to levels?

Postby jetjockey » Sun Jan 15, 2012 7:43 am

Hi, I was able to modify my function keys with the following code:

Code: Select all
Private Sub Workbook_Open()
        Application.OnKey "{F1}", "Showtold"
        Application.OnKey "{F2}", "Showcharts"
        Application.OnKey "{F3}", "Showarea"
        Application.OnKey "^{F4}", "mymacro"
End Sub


Code: Select all
Sub showtold()
   Sheets("told").Select
End Sub


Which works initially, but when I am editing a cell, the function keys are returning to the excel F keys. What do I need to do to have both level of the function keys work with my mapping of the F keys.

Thank you for your help

Pierre
  • 0

jetjockey
Rookie
 
Posts: 12
Joined: Jan 14, 2012
Location: Trenton On
Reputation: 0

Re: Function keys appear to have to levels?

Postby Sisyphus » Sun Jan 15, 2012 9:21 pm

Hi,
Look at it this way:
You are romping around where angels fear to tread, changing the functionality of the only thing that gives you whatever little control you have over the workings of your computer, i.e. the keys on your keyboard, without the slightest idea of how you are going to repair the damage you wreak. Some one - perhaps Microsoft in its design of Windows or the manufacturer of your computer - seems to have had the sense to undo your tinkering automatically. Consider yourself lucky! :D
Since you have tested this - perhaps a little involuntarily - you can now build on that knowledge. In addition to running your procedure on the Open event you can run it on the Worksheet_SelectionChange event which occurrs whenever you enter a cell on a worksheet. This is how you go about it:

1. Create a copy of your Workbook_Open procedure and name it something like
Public Sub SetFkeys()
End Sub

Place it in a normal code module, say "Module1"
To insert a code module right-click on the name of your VB Project (that is, the name of your workbook). In the dropdown that opens, select Insert / Module. It will be called Module1 by default if there aren’t any other modules with default names already.

2. Remove all code from your Workbook_Open event procedure and place it in the new procedure. In the Open event procedure, insert this function call:
Code: Select all
    SetFkeys


3. Double-click on the name of your worksheet in the Object Browser window. Above the code window you will see a drop-down with “(General)” selected. Change the selection to “Worksheet”. This will cause a blank Worksheet_SelectionChange procedure to be inserted by default. Write your function call in it. It will run every time you select a cell in your worksheet.

If you need the same functionality onm other sheets repeat the above steps for each step that you want to be similarly enabled.

This will make sure that you have the functionality you want. You must trust your computer to return the settings to what they should be whenever it switches off.

Best of luck! :D
  • 0

Have a great day! :D

Sisyphus
I do this for "honour and country" - much less of the latter, actually.
If I helped you, award points, plenty of them.
If I bored you, deduct points for being too long-winded. (I know, :lol)
Sisyphus
Former Moderator
 
Posts: 4454
Joined: Dec 7, 2011
Location: Shanghai
Reputation: 203
Excel Version: 2010


Return to Macros and VBA Questions

Who is online

Users browsing this forum: No registered users and 260 guests