How to View a List of All Open MS Word Documents through VBA Macro
You can switch from one open MS Word document to another by pressing CTRL + F6, in case you didn’t know.
But what if you have 16 Word documents open for some reason and you’d like to know their total number and view their file names so that you can decide whether to switch to them or perhaps close them off if you don’t need them anymore?
By writing a little VBA code, you can create a simple macro that would do exactly that.
(1) First select one of the open Word documents.
(2) Press ALT + F11 to display the VBA editing screen.
(3) Insert a new module by selecting Insert > Module from the menu.
(4) Insert the following subprocedure code in your Code Pane:
(5) Click the GREEN RUN ARROW on the toolbar, or press F5 key, or select Run > Run Sub/User Form from the menu to run the subprocedure.
If Word displays a macro selecting dialog box, select the macro and click Run.
After you run the macro, Microsoft Word will display a MsgBox (Message Box) like the following:
The exact content of the MsgBox will depend on the number of Word documents currently open.
P.S. If you’d like to learn how the VBA code exactly works, please leave a comment and I’d be happy to help.
Is there any other MS Word tasks and challenges that you cannot accomplish through the normal Word controls and tools but would like to do it through VBA code? Please let me know.
(Free image courtesy of Pippalou at morguefile.com)