2

I've inherited a workbook and a personal macro workbook that operate in conjunction with each other (drawing on a CSV and 2 LST files) to produce a report. The spreadsheet has rudimentary instructions, essentially:

  1. Sign on to the server
  2. Place the 3 (CSV and LST files) in the requisite subdirectory
  3. Open the report template
  4. Save the report template
  5. Open the personal macro workbook
  6. Hit "Ctrl+J"
  7. Follow the prompts
  8. Save and distribute the report

I open the files as required (with macros enabled) and followed the instructions but when I hit "Ctrl+J" nothing happens.

I searched through the VBA for both workbooks and can't find the command for "Ctrl+J" (or onkey or similar)

The original "developer" has left the organization so I am unable to speak to them.

Any suggestions on a place to start? Or alternatively h a way to trip all VBA code to notepad to search hidden depths on the workbook?

Thanks in advance.

6
  • In the Excel Trust Centre on your machine, under Macro Settings what do you have set? May 18, 2021 at 17:59
  • 1
    Ctrl+J is the shortcut to show VBA intellisense. So I don't think it can be used (I presume your macro is old). Go to Developer tab -> Macros. Select your macro, click Options. The shortcut key of the macro will be listed there. May 18, 2021 at 18:06
  • Macros are set to full trust.
    – DWGKNZ
    May 18, 2021 at 18:21
  • I suspected that to be a contributing issue (intellisense) but I don't know, and can't identify, which macro in either the workbook or personal macro workbook had used the shortcut. I can't find it within the VBA code.
    – DWGKNZ
    May 18, 2021 at 18:24
  • Do a search in the VBA code for the keyword SendKeys. Then, update your question with the line(s) around that keyword. May 18, 2021 at 18:58

1 Answer 1

2

When you record a macro using the Macro Recorder, you get to map a hotkey:

Excel's macro recorder dialog mapping Ctrl+Shift+J hotkey for Macro1

When you then look at the generated code, what you can see in the editor might look like this:

Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+Shift+J
'
    ...code...
End Sub

That's nice, but then if you deleted that comment, you can't quite know what the hotkey is anymore.

If you export that module and open it in Notepad, you'll see what the editor isn't showing you:

Sub Macro1()
Attribute Macro1.VB_ProcData.VB_Invoke_Func = "J\n14"
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+Shift+J
'
    ...code...
End Sub

This is the magic bit:

Attribute Macro1.VB_ProcData.VB_Invoke_Func = "J\n14"

All Excel hotkeys involve the Ctrl key. The capital J implies the use of the Shift key, and if you changed that attribute value to "e\n14" then the hotkey would become Ctrl+e.

Importing/exporting modules in the VBE is a royal pain in the neck. Rubberduck and its code inspections can help you there:

Rubberduck inspection warning about a missing annotation

Every single instance of this particular inspection result (for an Invoke_Func hidden attribute) means you're looking at a macro that is assigned a hotkey.

After right-clicking that inspection result and selecting "Add missing attribute annotation", the code module now looks like this:

'@ExcelHotkey J
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+Shift+J
'
    ...code...
End Sub

Now you can delete the macro-recorder generated comment, and let Rubberduck synchronize the @ExcelHotkey annotation with the appropriate hidden attribute value - all without leaving the VBE or exporting/importing anything.

Changing the annotation to @ExcelHotkey e would change the hotkey from Ctrl+Shift+J to Ctrl+e, after synchronizing attributes and annotation comments with Rubberduck.

3
  • Thanks, Mathieu. I didn't end up going down this route as I wasn't able to install RubberDuck onto an organizational PC. However, the generated comment had been removed in the Macro. I suspect this may have happened when Microsoft allocated ctrl+J to Intellisense.
    – DWGKNZ
    May 20, 2021 at 11:24
  • @DKGKNZ Microsoft didn't do anything, that was the author of the macro. Without Rubberduck you can still export the module and view and edit the hidden attribute value and re-import the modified module into your project - it's just a little bit more work than with Rubberduck. Side note, if you can get past the bogus "OMG YOU'RE DOWNLOADING AN EXECUTABLE FILE" warnings, Rubberduck installs per-user without requiring administrative privileges. May 20, 2021 at 13:18
  • Not sure what this has anything to do with IntelliSense though, and the VBIDE shortcut for parameter quick-info (aka IntelliSense) is Ctrl+i and no VBIDE hotkeys ever interferes with Excel. May 20, 2021 at 13:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .