One benefit I get from being on Twitter, and one of the reasons I like the service so much, is idea generation. People talk about features they’d like to see in a product, complain about features it’s lacking, and ask whomever is listening on Twitter for help figuring out how to use it to get a particular task done. While some of the suggestions are just plain crazy, many of them make perfect sense. Sometimes I slap my forehead after reading a tweet with an idea and wonder “Why didn’t I think of that?” Of course the answer is really simple. I don’t use the product/service the same way the author of the tweet does and therefore never realized the need. Necessity really is the mother of invention.
Here’s an example. I was scanning Outlook related tweets and ran across this one from Michael Mullen (@idiottech):
Microsoft Outlook needs a better way to close multiple emails. Closing each email is totally inefficient.
Michael has a good point, but one I’d never considered before because I rarely have more than two messages open at once. I can sympathize with Michael though because I frequently have multiple windows open in Outlook’s code editor and have found myself wishing there was a way to close them all without the need to close each one individually. While I can’t solve my problem, I can solve Michael’s.
[Note: As pointed out by JP (in comments below) Outlook already has the ability to close all open Windows with minimal effort. Sometimes I get too wrapped up in an idea and forget about existing features. In Outlook 2007 you can close all open windows by clicking File and selecting Close All Items. In Outlook 2010 the selection is on the ribbon’s View tab. This solution is unnecessary if you simply want to close all open windows. However, if you want to close some, but not all, then this solution may still be useful.]
The solution is a combination of a userform (userforms are what VBA calls custom dialog-boxes) and a macro that calls it. Here’s how it works. On opening, the userform builds and presents a list of all open message windows. Each item in the list includes a checkbox for selecting it. Michael can pick which items he wants to close or use the checkbox labeled “All” that appears just below the list to select all items with a single click. He can also choose to save any changes he’s made to the open items by checking the “Save” option. If he doesn’t choose “Save”, then by default the code will discard changes to each open item as it closes it. Clicking the “Close” button is the final step. As you might have guessed, this closes the selected message windows. Here’s an example. Say that Michael has ten messages open. Today it’d take him 10 clicks to close them all. With this he can do it in three clicks. One click to run the macro, another to check the “All” box which will select everything in the list, and finally the “Close” button to close them all. Oh, and this solution isn’t limited to message windows. It will work on appointments, contacts, tasks, and notes too, or any combination of open windows.
This solution comes in two parts.
Follow these instructions to add the userform to Outlook.
- Download the .zip file from this link
- Unzip the file
- Start Outlook
- Press ALT+F11 to open the Visual Basic Editor
- Click File and select Import File
- Navigate to the folder you saved the files to in step #2
- Select the file frmCloseMultiple
Follow these instructions to add this code to Outlook.
- If not already expanded, expand Microsoft Office Outlook Objects
- If not already expanded, expand Modules
- Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
- Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
- Edit the code as needed. I included comments wherever something needs to or can change
- Click the diskette icon on the toolbar to save the changes
- Close the VB Editor
Sub RunCloseAll() Dim objFrm As New frmCloseMultiple objFrm.Show vbModal Set objFrm = Nothing End Sub
Running the macros with a single click requires a bit more work. In Outlook 2003 and 2007 we’ll add a button to the toolbar. Outlook 2010 uses the ribbon, so for this version we’ll add a button to the Quick Access Toolbar (QAT).
Outlook 2003/2007. Follow these instructions to add toolbar buttons that run these macros.
Outlook 2010. Follow these instructions to add both macros to the QAT.