Home » excel » excel vba – Automatically display the IDE when a workbook is opened

excel vba – Automatically display the IDE when a workbook is opened

Posted by: admin March 9, 2020 Leave a comment

Questions:

I’m trying to automatically display the IDE when Excel is launched.

Is there a way to simulate a click on the “Visual Basic Editor” icon in the ribbon? I looked into Application.CommandBars but there’s nothing about the Ribbon.

Private Sub Workbook_Open()
    ' Display Visual Basic Editor
End Sub
How to&Answers:

The Commandbars object has an ExecuteMso method that allows you to “push” any Ribbon button, so:

Application.CommandBars.ExecuteMso ("VisualBasic")

As noted by Comintern, the Application qualification is necessary when using this in a Workbook_Open event, otherwise you’ll get an error 91.

To find the mso, go into the Quick Access toolbar’s Ribbon menu, find what you want and hover:

enter image description here

Answer:

It would be

Private Sub Workbook_Open()
    ' Display Visual Basic Editor
    Application.VBE.MainWindow.Visible = True 
End Sub

If you get Programmatic Access error:
Programmatic Access To Visual Basic Project Is Not Trusted – Excel