Close All VBE Windows (1 Viewer)

Status
Not open for further replies.

isladogs

MVP / VIP
Local time
Today, 18:06
Joined
Jan 14, 2017
Messages
18,186
I use the following function to close all VBE windows
Very useful when so many windows are left open you can't find anything.
It also significantly speeds up loading the VBE editor if it doesn't need to load lots of unwanted 'legacy' windows

Code:
Function CloseAllVBEWindows() 'CR v5207

'closes all VBE windows except this one!
'requires library 'Microsoft Visual Basic for Applications Extensibility'

'CR 02/02/2016 - added error handling to fix issue in 64-bit Office

On Error GoTo Err_Handler

Dim vbWin As VBIDE.Window

For Each vbWin In Application.VBE.Windows
     If (vbWin.Type = vbext_wt_CodeWindow Or _
         vbWin.Type = vbext_wt_Designer) And _
         Not vbWin Is Application.VBE.ActiveWindow Then
             vbWin.Close
     End If
 Next
 
Exit_Handler:
    Exit Function

Err_Handler:
    If Err.Number = 424 Then Resume Next 'object required
    MsgBox "Error " & Err.Number & " in CloseAllVBEWindows procedure: " & Err.Description
    Resume Exit_Handler

End Function

To use the code, just copy it to a module & run it

NOTE:
1. As stated in the code, add a reference to the library 'Microsoft Visual Basic for Applications Extensibility'
2. After running the function, all windows will be closed except the one containing the function itself.
Alternatively, to close all ALL windows, create an Autokeys macro shortcut for this function e.g.Ctl+Shift+X
 

CJ_London

Super Moderator
Staff member
Local time
Today, 18:06
Joined
Feb 19, 2013
Messages
16,553
A slight modification so you don't need to use the reference

Code:
'Dim vbWin As VBIDE.Window
 
Dim vbWin As Object
Const vbext_wt_CodeWindow = 0
Const vbext_wt_Designer = 1
 
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom