Question : Close all Forms in VB editor window (or activate particular module)

This ones a little more advanced, but hopefully someone will have an answer...I've been working on something that does all kinds of things to modules, macros, and such...but I have 1 problem that is killing me..

This line opens the vb editor window:
     Application.VBE.ActiveCodePane.Show
If I have an object variable...let's say iMod...and have it set as a particular module I can activate that module like this:
     iMod.Activate

Which is what I want to do and it works...but only if there were no forms open in the VB editor when it was closed...otherwise the vbeditor always opens up to a form (in design view) and the module I try to activate will not activate...it will always be a form if there was one open when the vbeditor was closed...otherwise it works fine.

Anyone know how I can close all the forms in the vb editor window, or make a particular module have the focus over the top of it (which is my main goal...to have that code pane have the focus...I don't care whether the form actually closes or not)

This is probably irrellevent, but here is my related code:
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
For n = 1 To ThisWorkbook.VBProject.VBComponents.Count
    Set iMod = ThisWorkbook.VBProject.VBComponents.Item(n)
        If iMod.CodeModule.countoflines > 0 Then
            cde = iMod.CodeModule.Lines(1, iMod.CodeModule.countoflines)
            cde = Replace(cde, Chr(10), "")
            If InStr(cde, MacToFind) > 0 Then
                MacPosition = InStr(cde, MacToFind)
                iMod.Activate
                Application.VBE.ActiveCodePane.Show
                iMod.Activate
            End If
        End If
Next X
Open in New Window Select All

Answer : Close all Forms in VB editor window (or activate particular module)

Hi Albert,

You can close all UserForms with the code below.

Cheers
Dave
1:
2:
3:
4:
5:
6:
Sub CloseWindows()
    Dim vbWin
    For Each vbWin In ThisWorkbook.VBProject.VBE.Windows
       If vbWin.Type = 1 Then vbWin.Close
    Next
End Sub
Open in New Window Select All
Random Solutions  
 
programming4us programming4us