Automatically display an IDE when opening a book

I am trying to automatically display an IDE when starting Excel.

Is there a way to simulate clicking on the Visual Basic Editor icon on the ribbon? I looked into Application.CommandBars , but nothing about that.

 Private Sub Workbook_Open() ' Display Visual Basic Editor End Sub 
+6
source share
2 answers

The Commandbars object has an ExecuteMso method that allows you to "click" any button on the ribbon, so:

 Application.CommandBars.ExecuteMso ("VisualBasic") 

As noted by the Comintern, the Application qualification is required when using this in the Workbook_Open event, otherwise you will receive an error message 91.

To find mso, go to the quick access panel in the feed menu, find the one you need and hover over it:

enter image description here

+7
source

It will be

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

If you get a Programmatic Access error: Program access to a Visual Basic project is not trusted - Excel

+4
source

All Articles