Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Re-Initiate Function Keys in Excel 1

Status
Not open for further replies.

FractalWalk

Technical User
Nov 18, 2002
141
US
I have several macros that I use all the time in Excel and so I have mapped them to function keys. However, I want to be able to toggle that ability on and off so that I can access the "original" function of those keys when I need to.

So I have built a menu with drop downs to "Turn on" and "Turn off" my functions. Here is an example of the code for each:

Code:
Public Sub Macro_Turn_On_Fkeys()
    Application.OnKey "{F1}", "Macro_VLookup"
End Sub

Public Sub Macro_Turn_Off_Fkeys()
    Application.OnKey "{F1}", ""
End Sub

That works great, but once I turn the functions off, how do I restore them to the original functions? If I close the workbook and re-open that resets them but I want a way to do that without closing out. Any thoughts?
 
Run the macro without second argument, i.e.:
Code:
Public Sub Macro_Reset_Fkeys()
    Application.OnKey "{F1}"
End Sub

combo
 
Maybe I wasn't clear. The second macro is to turn the function I assigned off, which I am intentionally trying to do. If I don't run it then the function I have assigned is still active. I want to de-activate my assigned function and re-activate the default function that Excel assigns when a workbook is opened.

For example, F5 opens a "Go To" box by default in Excel. I use F5 to run a special macro I wrote, but I want the option to re-assign F5 back to the "Go To" function. How do I do that?
 
It's ok, you have three options:
- Application.OnKey "{F1}", "Macro_VLookup" assigns custom macro to the key,
- Application.OnKey "{F1}", "" totally disables the key,
- Application.OnKey "{F1}" resets default action of the the key.

combo
 
Ah! I totally misunderstood what you said. Yes, that works perfectly. Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top