How to change Control-Y behavior in Excel-VBA's IDE

8

0

Excel VBA's IDE registers a Control-y as "cut this line of code".

By contrast, redo-ing is accomplished by Alt-e, R.

Is there any way to change this behavior and make Control-y be the much more common redo?

(For more on the default behavior, here is a link: http://www.pcreview.co.uk/threads/ctrl-y-in-vba-ide.2198613/)

Eliyahu

Posted 2015-02-18T20:19:09.800

Reputation: 465

Not really. Might be possible using some third party software to create a new hot key – Eric F – 2015-02-18T20:38:21.737

Application.Onkey method will do this for the application, but I don't think it works for the editor.. – Raystafarian – 2015-03-02T19:05:44.793

@gibberish: What is wrong with the answer below? – harrymc – 2018-08-01T06:03:15.757

I am looking for a cannonical/authoritative answer to whether ANYTHING is possible within the Excel/VBA object model. For example, there is an Excel VBE Object Model and I am wondering if the VBE can be directly programmed to solve this problem? *(I am open to the authoritative answer that you can't get there from here - if that is indeed the authoritative answer)*

– cssyphus – 2018-08-01T15:25:35.087

@gibberish: Nope, even anadd-in cannot intercept hotkeys.

– harrymc – 2018-08-04T16:41:49.240

Answers

2

In response to the question of :

I am wondering if the VBE can be directly programmed to solve this problem?

The answer unfortunately is negative. The only way to modify the behavior is by using add-ins whose capabilities are summed up by Microsoft as :

  • A startup module to trap the opening and closing of the add-in.
  • Some code to add our menu items to the commandbars on opening and remove them when closing
  • For the VBE, a class mosule to handle the menu items "Click" events
  • Some code to perform your menu's actions.

Specifically, intercepting hotkeys is not in the list.

The answer by Eliyahu is then still correct, and AutoHotKey (or AutoIt) is still the only solution.

harrymc

Posted 2015-02-18T20:19:09.800

Reputation: 306 093

Thanks @harrymc - I'm glad you returned to add this as an answer as it answered my query. – cssyphus – 2018-08-07T20:29:41.073

2

This autohotkey script I wrote seems to work:

#IfWinActive ahk_class wndclass_desked_gsk

^y::
Send {escape}
Send !e;
Send r
Send {escape}
Send {escape}
return

#IfWinActive

Eliyahu

Posted 2015-02-18T20:19:09.800

Reputation: 465

It works for me, but I see a flashing contextual menu appearing for a fraction of second or so when I press CTRL+Y... Is this the expected behaviour? Can I avoid it somehow? – Pere – 2019-07-02T11:53:39.510

@Pere The script replicates "Alt-e, r" so I don't think it can be avoided – Eliyahu – 2019-07-02T17:54:39.677

Yeah, I noticed that after inppecting the code and learning how Autohotkey works. Thanks for explaining, @Eliyahu – Pere – 2019-07-03T08:05:17.260

@Eliyahu where do you put this script please ???

I would also like re-map Ctrl_Y to ShiftCtrl_X where it should have been in the 1st place :-/

Though it's great that Ctrl_Z or Ctrl_V undoes it, it still wrecks the undo stack – Piecevcake – 2019-09-29T04:20:45.083

0

Excel VBA's IDE registers a Control-y as "cut this line of code".

By contrast, redo-ing is accomplished by Alt-e, R.

Darren_Stanley

Posted 2015-02-18T20:19:09.800

Reputation: 1