Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    jhg6308 is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2021
    Posts
    21

    Controlling which code windows open when opening VBA editor

    When opening the VBA editor, Access opens some module code windows.

    Which windows are opened doesn't seem to follow any rhyme or reason except that most of the opened modules were recently opened.

    In the past it was relatively easy to control this: editing and saving a module caused the VBA editor to remember the current IDE state regarding which windows were open at that time.

    This no longer seems to work. The net result is that when re-launching the VBA IDE I get a ton of windows unrelated to what I've been working on recently.

    Is there a way to force the VBA IDE to "remember" which code modules are open and reopen those, in the same order the next time the IDE is launched?

  2. #2
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    430
    you can reset and close all VBE windows:
    Code:
    ' add reference to (Menu->Tools->Reference) to:
    ' Microsoft Visual Basic for Applicatiion Extensebility X.X
    Public Sub CloseAllCodeWindowsOnly()
        Dim win As VBIDE.Window
        For Each win In Application.VBE.Windows
            If win.Type = vbext_wt_CodeWindow Then
                win.Close
            End If
        Next win
    End Sub

  3. #3
    Gustav's Avatar
    Gustav is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2025
    Posts
    32
    Having the VBE opened, press and hold Ctrl+F4 to close all code windows.
    Simple and fast.

  4. #4
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    430
    Quote Originally Posted by Gustav View Post
    Having the VBE opened, press and hold Ctrl+F4 to close all code windows.
    Simple and fast.
    Not on my Ms Access 2024, it closes the Active window, but not all.

  5. #5
    Gustav's Avatar
    Gustav is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2025
    Posts
    32
    Weird. Has worked "forever", also in Access 365.

  6. #6
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    430
    "forever"? I have VM and have 2003,2007,2010,2013.
    none of them close "all VBE" windows by Ctrl-F4.
    It just close the Active VBE window.

  7. #7
    Gustav's Avatar
    Gustav is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2025
    Posts
    32
    Alt+F4 closes the VBE window (any active window), not Ctrl+F4.

  8. #8
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    430
    Alt-F4 will close the VB Editor, just like you clicked the close (x) button of the editor.
    when you invoke the editor again (Ctrl-G, Alt-F11) you will see all windows are open (by going to Menu->Window).

  9. #9
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Pressing and holding Ctrl+F4 works for me in 365.
    Having said that, I still prefer to use code to close all active VBE windows at startup as doing that makes the VBE load far faster.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  10. #10
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    Why is this an issue? Is it because they're set to cascade? I can only see one window and although I can't say I've ever noticed, it is probably the last one worked on, or the last one that was open on top. I realize that most, if not all, windows are loaded but I don't see why that would be a problem - unless they open cascaded.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    The VBE loads all the code windows that were left open from the previous session. however they are arranged.
    If you have many open windows, the VBE will be far slower to load, usually taking several seconds - otherwise it is instantaneous.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  12. #12
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    I guess it depends on the hardware? I have one xl file with 45 standard modules, about 15 sheets with code modules and 4 userforms. Plus, it references the Personal.Xlsb file for other code. The code line count for the project is 11,730, so maybe that's not enough to cause any issues because my editor load speed seems fine.

    EDIT - make that 25 sheets.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    jhg6308 is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2021
    Posts
    21
    Quote Originally Posted by jojowhite View Post
    you can reset and close all VBE windows:
    [snip]
    That's great. It works for closing all windows, and they stay closed next time you open the IDE.

    Part 2 is how to tell the IDE to remember the currently open windows and open them again next time you start up.

  14. #14
    jhg6308 is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2021
    Posts
    21
    Quote Originally Posted by isladogs View Post
    The VBE loads all the code windows that were left open from the previous session. however they are arranged. [snip]
    Not in my experience for many years. It seems to get stuck on a particular set and reopens the same set.

    Making changes and saving sometimes changes which code windows reopen, but I've never been able to piece together any rhyme or reason.

    Even the VBA code answer from @jojowhite doesn't always have the same effect. First time I ran it it closed all code windows, and when I relaunched Access only the window containing the closeAllCodeWindows() method reopened. Since then it's been hit or miss if it works, and which windows reopen.

  15. #15
    jhg6308 is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2021
    Posts
    21
    I think I may have partly figured this out.

    Scenario 1: You launch Access, open a database and open the IDE (ALT+F11 or Ctrl+G)

    If you close only the IDE window (Alt+F4 in the IDE) and later reopen it, the code windows that were open at the time you closed the IDE will reopen exactly how you left them when you closed the IDE. You can close and reopen the IDE and this works consistently, as long as you don't exit Access altogether...

    Scenario 2: While in Scenario 1 you close the database (File/Close), or all of Access ("X" or ALT+F4 from the main database window):

    When you next reopen the database and open the IDE, a different set of code windows is opened.

    What I cannot seem to determine is which action causes Access to memorize the set of code windows that will open when the IDE is opened "fresh" on a database. This set does seem to occasionally change but I cannot correlate its changes to any action I perform.

    More Information

    It seems that which code windows get reopened on a "fresh" launch has to do with the most recently modified modules. I opened several modules, made insignificant whitespace changes and saved them. After closing and reopening the database, all the recently modified code windows reappeared.

    Now all I need to figure out is how to get Access to forget its "recently modified" list to start clean.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query Editor, Form Explorer, Rowsource editor
    By davegri in forum Sample Databases
    Replies: 24
    Last Post: 04-25-2023, 08:09 AM
  2. Replies: 3
    Last Post: 09-17-2022, 06:00 PM
  3. Replies: 9
    Last Post: 01-29-2019, 05:28 PM
  4. Replies: 2
    Last Post: 11-09-2016, 10:41 AM
  5. Replies: 3
    Last Post: 12-02-2014, 09:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums