0

In my Excel file, i have both a module and a class module. When i open VBA editor, the class module's code loads into the main window and if i want to see the module's code, i have to click on "+ Modules" folder and select my module.

How can i set up the editor to load the module's code on startup?

2 Answers 2

1

Sorry, this is a work around as I have not found any options to do what you requested. The only way I know to get it to open the specific module you want is to open the Macro Window, choose the macro which is associated with the module you want opened, then click Edit.

Keyboard shortcut to open the Macro Window is Alt + F8. Then press E while still holding Alt to Edit the first macro.

enter image description here

1
  • Alt+F8+E shortcut will definitelly help (i edited the answer to include Alt+E to edit the first macro), if no better answer will come in a day, i'll accept this one :)
    – Aprillion
    Jun 27, 2012 at 14:13
1

This doesn't answer your question, but it removes a step from the way you currently do it. Use the "Toggle Folders" button at the top of the Project Explorer, to list all VBA objects in alpha order instead of by type. It's the one under "VBA-Project" in the picture:

Toggle Folders button

Edit: One other thought is you could have code in the Workbook_Open or Workbook_Activate event that would shift the view to the Module. I think it would have limited utility, but might be worth trying something like this in the ThisWorkbook module:

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Me.VBProject.VBComponents("Module1").Activate
End Sub

Note that you have to go into the "Trust Center," choose "Trust Center Settings" and then "Macro Settings" and check "Trust access to the VBA project model" or you'll get a runtime error of "Programmatic Access to Visual Basic Project is not trusted."

1
  • i'll have to see which object will be open on startup, but it is a persistent setting, so +1 for saving at least 1 doubleclick in any case
    – Aprillion
    Jun 27, 2012 at 18:41

You must log in to answer this question.

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