How to get a reminder when "Insert" key is presed

Category: word for developers


CNL777 on Tue, 21 Mar 2017 09:49:20

Hi everyone,

The "Insert" key in my Word is assigned to control the overtype mode. 

I find I constantly press "Insert" by accident so the typing mode is changed to overtype. Many times, I notice it only after texts being replaced. 

This is annoying, but I don't want to disable the "Insert" key either, for I could use it in the future.

So I want to know the macro codes to detect the press of "Insert" key. Then I can choose to turn off the overtype mode before everything is too late. 

Please help me!!!




Deepak Saradkumar Panchal on Wed, 22 Mar 2017 02:34:07

Hi VC77,

you can try to refer code below.

Code for Module1:

Sub AddKeyBinding() 
    With Application 
         ' \\ Do customization in THIS document
        .CustomizationContext = ThisDocument 
         ' \\ Add keybinding to this document Shorcut: Alt+0
        .KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyAlt, wdKey0), _ 
        KeyCategory:=wdKeyCategoryCommand, _ 
    End With 
End Sub 

Code for Module:

Option Explicit 
 ' \\ Test sub for keybinding
Sub TestKeybinding() 
    MsgBox "We have a winner", vbInformation, "Succes" 
End Sub 


Add Keybinding to document to launch Macro

KeyBindings.Key Method (Word)

Refer link below to get the list of key codes.

BuildKeyCode Method

you just need to replace the desire key and try to run the module 1.

then after when you press that key , it will run the code and display the message from module 2.

you can also keep all the code in module1, you can modify it as per your requirement.



CNL777 on Wed, 22 Mar 2017 03:13:04

Hi Deepak,

Thanks a million. This is exactly what I need.

And thank you for the references. I will read them and study the Method.

Have a good day!