locked
How to close all openVBA code windows RRS feed

  • Question

  • When I make a project wide change by using Search and Replace ( or any other process where I end up with a lot of open windows in the VBE code panel, I'd like to close them more easily than having to click the close button on each one.  I can't seem to find a Close All action.  Is there one, or should I look through the keyboard shortcuts?

    Thanks.

    Marj Weir

    Sunday, January 31, 2016 12:04 AM

Answers

  • If you want to do it programatically within a procedure or function calling the following should close all open modules, saving any current changes.  If you don't want changes saved, them change the final argument of the Close method of the DCmd object accordingly:

    Public Sub CloseAllModules()

        Dim n As Integer
        Dim mods As Modules
        
        Set mods = Application.Modules
        
        ' loop backwards through all open modules
        ' and close and save each
        For n = mods.count - 1 To 0 Step -1
            DoCmd.Close acModule, mods(n).Name, acSaveYes
        Next n
        
    End Sub

    Ken Sheridan, Stafford, England



    Sunday, January 31, 2016 4:54 PM

All replies

  • Press and hold CTRL+F4..
    Sunday, January 31, 2016 1:34 AM
  • Hi Marj. I don't have an answer for you. I was just surprised by your request. I never experienced having to worry about "closing" the code window because I always view them in full screen. You make me wonder how others use the IDE. Cheers!
    Sunday, January 31, 2016 1:34 AM
  • You make me wonder how others use the IDE.

    Hi Marj and DB guy,

    I really don't care about open or closed modules, but if I had to make a decision, I would choose for open. I will explain this.

    All the users of all my appliucations NEVER go into development mode, so this question is not relevant for them.

    The difference between an open and closed module is that an open module is a member of the Modules collection. Many times I want to inspect how my different applications (now 92) behave. For that purpose I loop through all applications. Within an application is it not sufficient to loop through the Modules collection, because you then only catch the open modules. Instead I collect all modules from the MSysModule tables, and then go to the individual modules. If a module is opened, I can use it directly, else I have to open the module first explicitely, which gives a lot of screen flickering. That is why I like all modules open.

    On the other hand, when working in one application in the IDE with all modules open, I find it sometimes a chaos with all that open windows. Then I close a couple of them ad hoc.

    By the way, I never inspect Form modules. They are always closed. Because I use generalized forms, defined in a referenced database, I only need to inspect that referenced database to study the behaviour of forms.

    Imb.


    • Edited by Imb-hb Sunday, January 31, 2016 8:57 AM some typos
    Sunday, January 31, 2016 8:22 AM
  • If you want to do it programatically within a procedure or function calling the following should close all open modules, saving any current changes.  If you don't want changes saved, them change the final argument of the Close method of the DCmd object accordingly:

    Public Sub CloseAllModules()

        Dim n As Integer
        Dim mods As Modules
        
        Set mods = Application.Modules
        
        ' loop backwards through all open modules
        ' and close and save each
        For n = mods.count - 1 To 0 Step -1
            DoCmd.Close acModule, mods(n).Name, acSaveYes
        Next n
        
    End Sub

    Ken Sheridan, Stafford, England



    Sunday, January 31, 2016 4:54 PM
  • Best investment: MZ Tools http://www.mztools.com/

    peter n roth - http://PNR1.com, Maybe some useful stuff

    Sunday, January 31, 2016 9:26 PM
  • The "Window" menu in the VBA editor used to have an option at the bottom of the list of open windows to "Close All Windows".

    I, too, have been looking for this because I found it very useful in earlier versions of Access. I'm using Microsoft VBA 7.1 from Access 2016 and I can't find it.

    Regards,

    Richard

    Wednesday, May 10, 2017 8:12 AM
  • Thanks.

    Can you describe more fully (with some VBA) the utility and structure of a referenced database.

    Please.

    Michael

    Wednesday, September 12, 2018 8:39 PM
  • Can you describe more fully (with some VBA) the utility and structure of a referenced database.

    Hi Michael,

    Better start a new thread with your question instead of extending an old closed one.

    Imb.

    Wednesday, September 12, 2018 9:19 PM