Prevent VBA editor close from causing Excel WindowState from changing

Nick Vittum

New Member
Joined
Apr 2, 2020
Messages
26
Office Version
  1. 365
Platform
  1. Windows
This may be a "Duh!" to the rest of you, but it seems I never noticed it before: If the Excel window is minimized, and you're working in VBA editor, and then you close the editor, the Excel WindowState changes to xlNormal.

Currently I'm working on a Workbook that remains minimized most of the time (data entry is all done through a userform). While I'm tweaking the workbook, I'm opening and closing the VBA editor frequently. I want to prevent the Excel WindowState from changing: if I have it minimized, I want it to stay that way (and for that matter, if I have it Maximized, I want it to stay that way).

I'm not sure exactly what code to write to prevent this, and more importantly, not sure where to put it. I tried putting this in the Workbook's "Workbook_WindowResize" event, just to see if that was the right place—
VBA Code:
    If Application.VBE.MainWindow.Visible = False Then Wn.WindowState = xlMinimized
As might be expected, that prevented the Excel window from showing at all unless the VBA window was also visible (just a .1 second flash, if I tried to show it). So then I tried replacing that bit with this—
Code:
    If Application.VBE.MainWindow.Visible = False And Wn.WindowState = xlMinimized Then
        Wn.WindowState = xlMinimized
—but this time the result was nothing at all.

So: Is there an actual "Close Window" event for the VBA window somewhere, where I should be putting this code? And/or how can I reword my code to get the effect I want?

Thanks!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
If you are working in Excel on the editor, then Excel assumes you intend to continue working in the application when you close the editor, so it automatically restores the worksheet window. I don't know of a setting you can use to prevent that window from appearing when you close the editor, but if you don't want the window, then just minimize it.
 
Upvote 0

Forum statistics

Threads
1,223,727
Messages
6,174,139
Members
452,546
Latest member
Rafafa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top