Rubberduck: Method shortcut keys lost on module rewrite

Created on 2 Sep 2017  路  6Comments  路  Source: rubberduck-vba/Rubberduck

When using quick fixes in RD, method shortcut keys are sometimes (always?) lost.

Tentative steps to reproduce:

  1. Create a method that is implicitly public.
  2. Assign it a shortcut key via the Macros button in the Developer tab.
  3. Use RD's code inspector to quick fix the implicitly public method to explicitly public.
  4. The shortcut key no longer works/is not available in the Macros button.

Possible solutions:

There appear to be two methods here that would work
https://social.msdn.microsoft.com/Forums/en-US/7681fa96-4f83-4747-93e1-281db81e316d/assigning-keyboard-shortcut-to-vba-macro-programmatically?forum=isvvba

bug enhancement feature-annotations has-workaround

Most helpful comment

Also, I think that MSDN fix only applies to Excel.

If the attribute annotations included the shortcut key, then the rewriter would be able to reinstate the VB_Attribute.

All 6 comments

I think that's a VBE quirk - editing the signature of the method, whether manually or with Rubberduck, tends to obliterate the VB_Attributes (and the shortcut key is a VB_Attribute).

Also, I think that MSDN fix only applies to Excel.

If the attribute annotations included the shortcut key, then the rewriter would be able to reinstate the VB_Attribute.

@ThunderFrame TIL. And as a bonus you get the hotkey visibly documented in the editor.

This should be fixed by upcoming PR #4686

Losing the attribute should be already fixed now, but @ThunderFrame's idea should still end up being implemented:

'@HotKey("T")
Public Sub DoSomething()
Attribute DoSomething.VB_ProcData.VB_Invoke_Func = "T\n14"
End Sub

The hotkey string/character is case-sensitive, and the Ctrl modifier is implicit. The attribute value simply needs to take (+validate) that character, append "\n14" (which presumably stands for the Ctrl modifier key).

Actually the annotation should be @ExcelHotKey, since it's apparently Excel-specific. https://stackoverflow.com/a/36961298/1188513

Was this page helpful?
0 / 5 - 0 ratings