Over the past few days, several people asked me how to get a count of the messages you have selected. It's easy in Outlook on the web as the count is shown in the reading pane area, but Outlook doesn't show the count. The Status Bar will show you the total number of items and total unread, but not the number selected.
Fortunately, you won't be relegated to counting the messages yourself as a macro can get it for you. If you are using a work computer and cannot use a macro, you can copy the selection (Ctrl+C) and paste into Notepad or Excel then subtract 1 from the line count.
To use the copy and paste method with Calendar, Contacts, or Tasks, you will need to use a List view.
If you are using Notepad, you'll need to enable the Status Bar on the View menu. Click in the last line and get the Line count from the status bar.
This macro will work on Mail, Calendar, Contacts, or Tasks.
To use: Add the macro to the Quick Access Toolbar or ribbon, select the items using Shift+Click or Ctrl+Click then click the macro button.
It works with non-contiguous selections but will not count messages within a selected conversation. You'll need to select each message within the conversation to count them.
As you can see from the screenshot, the unread message count is in the group header. You could click on the Unread bar in the Conversation group header to mark the messages in the group unread and get the count without using Copy or the macro, but it only marks messages in that are in the folder, not replies. The macro will get the selected items, even if they are in another folder.
Sub countSelection() Dim currentExplorer As Explorer Dim Selection As Selection Set currentExplorer = Application.ActiveExplorer Set Selection = currentExplorer.Selection MsgBox Selection.count & " items are selected." Set Selection = Nothing Set currentExplorer = Nothing End Sub
How to use the macros on this page
First: You need to have macro security set to the lowest setting, Enable all macros during testing. The macros will not work with the top two options that disable all macros or unsigned macros. You could choose the option Notification for all macros, then accept it each time you restart Outlook, however, because it's somewhat hard to sneak macros into Outlook (unlike in Word and Excel), allowing all macros is safe, especially during the testing phase. You can sign the macro when it is finished and change the macro security to notify.
To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, look at Tools, Macro Security.
After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
Macros that run when Outlook starts or automatically need to be in ThisOutlookSession, all other macros should be put in a module, but most will also work if placed in ThisOutlookSession. (It's generally recommended to keep only the automatic macros in ThisOutlookSession and use modules for all other macros.) The instructions are below.
The macros on this page should be placed in a module.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
More information as well as screenshots are at How to use the VBA Editor
Hi, Just want to say thanks for the openness of this site. Found so many things useful as a vba newbie and have subscribed.
First visited a few months ago and I’m sure I could launch my vba scripts for this outlook session without going in and out of outlook. But I’ve forgot how to do this…tried finding how to do it. Something to do with outlook application startup?
Many Thanks
Gareth