Can I capture and emulate a KeyDown event in Excel VBA?

前端 未结 2 1226
抹茶落季
抹茶落季 2021-02-06 09:25

Arun Singh gave a great answer to a similar question (Is there any event that fires when keys are pressed when editing a cell?). I want to set a flag to prevent execution of Sel

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-06 09:41

    I need to adjust the above to work with Worksheet_Change and Tab key as basically when tab key is pressed then changes the Target (when A2 is edited and Tab key pressed, Change event shows cell B2) which I want to avoid.

    I have changed the key part to:

            If iKeyCode = vbKeyTab Then   '<~~ Tab
                SendKeys "{TAB}"
                CancSelEvnt = True
            Else
                CancSelEvnt = False
            End If
    

    but am struggling to get any result on that?

    When I press Tab key then my Change event does not call Sub StartKeyWatch() at all. also calling Sub StartKeyWatch() from Worksheet_Change directly does not seem to be doing anything...

    what am I missing here?

    thanks, mkvarious

提交回复
热议问题