8

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/)

  • Not really. Might be possible using some third party software to create a new hot key – Eric F Feb 18 '15 at 20:38
  • Application.Onkey method will do this for the application, but I don't think it works for the editor.. – Raystafarian Mar 2 '15 at 19:05
  • Related: stackoverflow.com/questions/7497347/… – Eliyahu Aug 14 '15 at 17:56
  • @gibberish: What is wrong with the answer below? – harrymc Aug 1 '18 at 6:03
  • 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 Aug 1 '18 at 15:25
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
  • 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 Jul 2 at 11:53
  • @Pere The script replicates "Alt-e, r" so I don't think it can be avoided – Eliyahu Jul 2 at 17:54
  • Yeah, I noticed that after inppecting the code and learning how Autohotkey works. Thanks for explaining, @Eliyahu – Pere Jul 3 at 8:05
  • @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 Sep 29 at 4:20
2
+50

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.

  • Thanks @harrymc - I'm glad you returned to add this as an answer as it answered my query. – cssyphus Aug 7 '18 at 20:29
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.