Everyone wants a unified inbox. Outlook doesn't have anything built in, search folders are per-message store only, and won't work for multiple email accounts. Instant search will search multiple data files, but you need to create the instant search each time you want to use it.
This is a solution to a very popular question of how to create a Unified Inbox in Outlook 2010. It was posted in the TechNet forums by oju2. While not quite the same as a true Unified Inbox for all email accounts, it has one advantage a true unified inbox does not offer: a very easy way to filter out the mail you don't want to see in a unified view by adding additional queries to the txtSearch line in each macro.
This solution could easily be adapted to apply any frequently used search conditions to a folder.
To use, press Alt+F11 to open the VBA editor, expend Project1 and paste the code into ThisOutlookSession. Add Buttons to Your ribbon or QAT to call the macros to quickly enable the Unified Inbox search when needed. Remember: you need to have macro security set on Low, Warn, or sign the macros using SelfCert.
See How to use Outlook’s VBA Editor for complete details.
1) Type the following in the search box: folder: (Inbox) received: (this week)
2) Press Ctr+Alt+A to or click All Mailboxes button (Outlook 2013) or All Mail Folders (Outlook 2010).
3) Hit enter and you should see your Unified inbox for all mails received this week.
A more elaborate solution to automate this is to do a Macro. This is the code you need:
The code for a UNIFIED INBOX:
Sub UnifiedInbox() Dim myOlApp As New Outlook.Application txtSearch = "folder:Inbox received: (this week)" myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders Set myOlApp = Nothing End Sub
The code for a UNIFIED SENT BOX:
Sub UnifiedSentbox() Dim myOlApp As New Outlook.Application txtSearch = "folder: (Sent Mail) sent: (this week)" myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders Set myOlApp = Nothing End Sub
Valid Search Scopes
In Outlook 2010 and Outlook 2013, you can choose between the following search scopes:
|olSearchScopeCurrentFolder||Limit the search to the currently selected folder.|
|olSearchScopeSubfolders||Limit the search to the currently selected folder and its subfolders. To search all folders in one data file, select the top level of the pst.|
|olSearchScopeAllFolders||Search all folders (of the current folder type). This search includes all data stores that are enabled for search.|
|olSearchScopeAllOutlookItems||Search all Outlook items in all folders in stores that are enabled for search.|
In Outlook 2007, you are limited to olSearchScopeAllFolders and olSearchScopeCurrentFolder
Create a macro for any frequently used Instant Search
You can easily use this macro to create a frequently used search and assign it to a button. You can use instant search to get the criteria then copy and paste it in txtSearch line. When a search query includes double quotes, replace them with parenthesis.
For example, category:="MTWT" becomes category:(MTWT)
Sub SearchByCategory() Dim myOlApp As New Outlook.Application txtSearch = "category:(Business)" myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders Set myOlApp = Nothing End Sub
Use this code to search (in the current folder) for mail received within the last 7 days.
Sub LastSevenDays() Dim myolApp As New Outlook.Application Dim tDate As Date tDate = Date - 7 '7 days ago txtSearch = "folder:Inbox received: (>" & tDate & ")" myolApp.ActiveExplorer.Search txtSearch, olSearchScopeCurrentFolder Set myolApp = Nothing End Sub
To find messages between two dates, use this string:
txtSearch = "received: (" & Date - 14 & ".." & Date - 7 & ")"
Merged with the code to paste the clipboard contents into a message from Paste clipboard contents using VBA, this string sample would search for the text that is on the clipboard. Combine it with predefined search terms like this:
txtSearch = "received: (" & tDate & ".." & Date & ") " & strPaste
Don't forget to set a Reference to the Forms library. If you receive a "User-defined type not defined" you are missing the reference to Microsoft Forms 2.0 Object Library. If its not listed, add C:\Windows\System32\FM20.dll or C:\Windows\FM20.dll as a reference. Paste clipboard contents using VBA has screenshots and more details instructions.
Sub SearchClipboard() Dim myOlApp As New Outlook.Application Dim strPaste Dim DataObj As MSForms.DataObject Set DataObj = New MSForms.DataObject DataObj.GetFromClipboard strPaste = DataObj.GetText(1) txtSearch = strPaste myOlApp.ActiveExplorer.search txtSearch, olSearchScopeAllFolders Set myOlApp = Nothing End Sub