none
Macro to search All Junk from multiple IMAP/POP3/Exchange accounts RRS feed

  • Question

  • I am finally making the switch from Windows Live Mail to Outlook 2013. The main reason I kept WLM is because of the included Default Search folders such as "All Inbox" "All Junk" "All Mail" etc. I have found some articles to help search in a particular folder over multiple accounts. The problem I'm running into is that Outlook.com has a junk folder named "Junk E-mail" and Google has its junk named "Spam"

    Here is my code:

    Sub UnifiedJunkbox()
    Dim myOlApp As New Outlook.Application
    txtSearch = "folder: 'Junk E-Mail','Spam'"
    myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders
    Set myOlApp = Nothing
    End Sub

    How can I set up a search filter to view All junk messages from All accounts? I am not going to move or copy every single message to common folders just to accomplish this, that is redundant and ridiculous; I want to keep the messages where they belong and just be able to see a combined view.

    Saturday, December 14, 2013 4:22 AM

Answers

  • Hello Michael,

    It looks like you need to use the AdvancedSearch method of the Application class instead. It allows specifying multiple folders for a scope (see the first parameter). To get the folder path for all junk folders from various stores you can use the following code (a raw sketch):

    Dim ns As Outlook.NameSpace
    Dim sts As Outlook.Stores
    ns = OutlookApp.GetNamespace("MAPI")
    sts = ns.Stores
    Dim folders As String
    For Each st As Outlook.Store In sts
        folders += st.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderJunk).FolderPath
    Next

    As you may see the Stores collection is used for iterating over all stores. The Store class from the Outlook Object Model provides the GetDefaultFolder method which represents the default folder in the store and that is of the type specified by the FolderType argument. Thus you will get a junk folder for each store. Then you can use the FolderPath property which returns the path of the current folder (the result string can be used for the scope argument).

    It is recommended that the folder path  is enclosed within single quotes. Otherwise, the search might not return correct results if the folder path contains special characters including Unicode characters. To specify multiple folder paths, enclose each folder path in single quotes and separate the single quoted folder paths with a comma. For example:

    Scope = "'" & Application.Session.GetDefaultFolder(olFolderInbox).FolderPath _  
        & "','" & Application.Session.GetDefaultFolder(olFolderSentMail).FolderPath & "'"
    
    You can read more about the Outlook Advanced search in one of my articles Advanced search in Outlook programmatically: C#, VB.NET.
    Saturday, December 14, 2013 10:40 AM
  • Hello Michael,

    Note, the Outlook Object Model is common for all kind of add-ins (macros, shared, VSTO, ADX based). There is no need to use Add-in Express. Moreover, the C# and VB.NET source code listed in the blog post shows the way how you can use the AdvancedSearch method in a VSTO based add-in:

    C# and VSTO:

    string advancedSearchTag = "Our first advanced search in Outlook";
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    // ...
    private void RunAdvancedSearch(Outlook.Application Application, string wordInSubject)
    {
        string scope = "Inbox";
        string filter = "urn:schemas:mailheader:subject LIKE '%" + wordInSubject + "%'";
        Outlook.Search advancedSearch = null;
        Outlook.MAPIFolder folderInbox = null;
        Outlook.MAPIFolder folderSentMail = null;
        Outlook.NameSpace ns = null;
        try
        {
            ns = Application.GetNamespace("MAPI");
            folderInbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            folderSentMail = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
            scope = "'" + folderInbox.FolderPath + "','" + 
                                                       folderSentMail.FolderPath + "'";
            advancedSearch = Application.AdvancedSearch(
                                                scope, filter, true, advancedSearchTag);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "An eexception is thrown");
        }
        finally
        {
            if (advancedSearch != null) Marshal.ReleaseComObject(advancedSearch);
            if (folderSentMail != null) Marshal.ReleaseComObject(folderSentMail);
            if (folderInbox != null) Marshal.ReleaseComObject(folderInbox);
            if (ns != null) Marshal.ReleaseComObject(ns);
        }
    }
     
    void Application_AdvancedSearchComplete(Outlook.Search SearchObject)
    {            
        Outlook.Results advancedSearchResults = null;
        Outlook.MailItem resultItem = null;
        System.Text.StringBuilder strBuilder = null;
        try
        {
            if (SearchObject.Tag == advancedSearchTag)
            {
                advancedSearchResults = SearchObject.Results;
                if (advancedSearchResults.Count > 0)
                {
                    string[] version = Application.Version.Split('.');
                    int hostMajorVersion = Convert.ToInt32(version[0]);
                    if (hostMajorVersion > 10)
                    {
                        object folder = SearchObject.GetType().InvokeMember("Save",
                                                System.Reflection.BindingFlags.Instance |
                                                System.Reflection.BindingFlags.InvokeMethod |
                                                System.Reflection.BindingFlags.Public,
                                                null, SearchObject, 
                                                new object[] { advancedSearchTag });
     
                    }
                    else
                    {
                        strBuilder = new System.Text.StringBuilder();
                        strBuilder.AppendLine("Number of items found: " + 
                                               advancedSearchResults.Count.ToString());
                        for (int i = 1; i < = advancedSearchResults.Count; i++)
                        {
                            resultItem = advancedSearchResults[i] as Outlook.MailItem;
                            if (resultItem != null)
                            {
                                strBuilder.Append("#" + i.ToString());
                                strBuilder.Append(" Subject: " + resultItem.Subject);
                                strBuilder.Append(" \t To: " + resultItem.To);
                                strBuilder.AppendLine(" \t Importance: " + 
                                                       resultItem.Importance.ToString());
                                Marshal.ReleaseComObject(resultItem);
                            }
                        }
                        if (strBuilder.Length > 0)
                            System.Diagnostics.Debug.WriteLine(strBuilder.ToString());
                        else
                            System.Diagnostics.Debug.WriteLine(
                                                      "There are no Mail items found.");
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("There are no items found.");
                }
           }
       }
       catch (Exception ex)
       {
           MessageBox.Show(ex.Message, "An exception is occured");
       }
       finally
       {
           if (resultItem != null) Marshal.ReleaseComObject(resultItem);
           if (advancedSearchResults != null) 
               Marshal.ReleaseComObject(advancedSearchResults);
       }
    }

    VB.NET and VSTO:

    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    ' ...
    Dim advancedSearchTag As String = "Our first advanced search in Outlook"
     
    Private Sub RunAdvancedSearch(Application As Outlook.Application, wordInSubject As String)
        Dim scope As String = "Inbox"
        Dim filter As String = "urn:schemas:mailheader:subject LIKE '%" + wordInSubject + "%'"
        Dim advancedSearch As Outlook.Search = Nothing
        Dim folderInbox As Outlook.MAPIFolder = Nothing
        Dim folderSentMail As Outlook.MAPIFolder = Nothing
        Dim ns As Outlook.NameSpace = Nothing
        Try
            ns = Application.GetNamespace("MAPI")
            folderInbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
            folderSentMail = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail)
            scope = "'" + folderInbox.FolderPath + "','" + folderSentMail.FolderPath + "'"
            advancedSearch = Application.AdvancedSearch(scope, filter, True, advancedSearchTag)
        Catch ex As Exception
            MessageBox.Show(ex.Message, "An eexception is thrown")
        Finally
            If Not IsNothing(advancedSearch) Then Marshal.ReleaseComObject(advancedSearch)
            If Not IsNothing(folderSentMail) Then Marshal.ReleaseComObject(folderSentMail)
            If Not IsNothing(folderInbox) Then Marshal.ReleaseComObject(folderInbox)
            If Not IsNothing(ns) Then Marshal.ReleaseComObject(ns)
        End Try
    End Sub
     
    Private Sub adxOutlookEvents_AdvancedSearchComplete(SearchObject As Outlook.Search) 
                                              Handles Application.AdvancedSearchComplete
        Dim advancedSearchResults As Outlook.Results = Nothing
        Dim resultItem As Outlook.MailItem = Nothing
        Dim strBuilder As System.Text.StringBuilder = Nothing
        Try
            If (SearchObject.Tag = advancedSearchTag) Then
                advancedSearchResults = SearchObject.Results
                If (advancedSearchResults.Count > 0) Then
                    Dim version As String() = Application.Version.Split(".")
                    Dim hostMajorVersion As Integer = Convert.ToInt32(version(0))
                    If (hostMajorVersion > 10) Then
                        Dim folder As Object = SearchObject.GetType().InvokeMember("Save",
                                                 System.Reflection.BindingFlags.Instance Or
                                                 System.Reflection.BindingFlags.InvokeMethod Or 
                                                 System.Reflection.BindingFlags.Public,
                                                 Nothing, SearchObject, 
                                                 New [Object]() {advancedSearchTag})
                    Else
                        strBuilder = New System.Text.StringBuilder()
                        strBuilder.AppendLine("Number of items found: " + 
                                               advancedSearchResults.Count.ToString())
                        For i As Integer = 1 To advancedSearchResults.Count Step 1
                            resultItem = CType(advancedSearchResults(i), Outlook.MailItem)
                            If Not IsNothing(resultItem) Then
                                strBuilder.Append("#" + i.ToString())
                                strBuilder.Append(" Subject: " + resultItem.Subject)
                                strBuilder.Append(" To: " + resultItem.To)
                                strBuilder.AppendLine(" Importance: " + 
                                                        resultItem.Importance.ToString())
                                Marshal.ReleaseComObject(resultItem)
                            End If
                        Next
                        If (strBuilder.Length > 0) Then
                            System.Diagnostics.Debug.WriteLine(strBuilder.ToString())
                        Else
                            System.Diagnostics.Debug.WriteLine( _
                                                    "There are no Mail items found.")
                        End If
                    End If
                Else
                    System.Diagnostics.Debug.WriteLine("There are no items found.")
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "An exception is occured")
        Finally
            If Not IsNothing(resultItem) Then Marshal.ReleaseComObject(resultItem)
            If Not IsNothing(advancedSearchResults) Then 
                Marshal.ReleaseComObject(advancedSearchResults)
            End If
        End Try
    End Sub
    You can use the same code for VBA macros. Why do you need to purchase something else?


    Monday, December 16, 2013 6:37 AM

All replies

  • Hello Michael,

    It looks like you need to use the AdvancedSearch method of the Application class instead. It allows specifying multiple folders for a scope (see the first parameter). To get the folder path for all junk folders from various stores you can use the following code (a raw sketch):

    Dim ns As Outlook.NameSpace
    Dim sts As Outlook.Stores
    ns = OutlookApp.GetNamespace("MAPI")
    sts = ns.Stores
    Dim folders As String
    For Each st As Outlook.Store In sts
        folders += st.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderJunk).FolderPath
    Next

    As you may see the Stores collection is used for iterating over all stores. The Store class from the Outlook Object Model provides the GetDefaultFolder method which represents the default folder in the store and that is of the type specified by the FolderType argument. Thus you will get a junk folder for each store. Then you can use the FolderPath property which returns the path of the current folder (the result string can be used for the scope argument).

    It is recommended that the folder path  is enclosed within single quotes. Otherwise, the search might not return correct results if the folder path contains special characters including Unicode characters. To specify multiple folder paths, enclose each folder path in single quotes and separate the single quoted folder paths with a comma. For example:

    Scope = "'" & Application.Session.GetDefaultFolder(olFolderInbox).FolderPath _  
        & "','" & Application.Session.GetDefaultFolder(olFolderSentMail).FolderPath & "'"
    
    You can read more about the Outlook Advanced search in one of my articles Advanced search in Outlook programmatically: C#, VB.NET.
    Saturday, December 14, 2013 10:40 AM
  • Thank-you, I have gotten closer.

    I had to modify your code a little as VBA doesn't like the += switch. The code works up until it tries to search. It gives me a run time error of '-2147221241 (80040107) The attempted operation failed. An object could not be found.'

    Dim ns As Outlook.NameSpace
    Dim sts As Outlook.Stores, st As Outlook.Store
    Dim folders As String
    Dim i As Integer
    Dim sch As Outlook.Search
    
        Set ns = Outlook.GetNamespace("MAPI")
        Set sts = ns.Stores
        
        folders = folders & "'"
        
        For Each st In sts
    
            i = i + 1
    
            folders = folders & st.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderJunk).FolderPath
            
            'Add quotes and commas
            If i < sts.Count Then
    
                folders = folders & "','"
                
            Else
            
                folders = folders & "'"
    
            End If
    
        Next
        
        Set sch = Outlook.AdvancedSearch(folders)



    Saturday, December 14, 2013 10:19 PM
  • Hello Michael,

    Please check out the following key points:


    Sunday, December 15, 2013 6:40 AM
  • I viewed the article and the code requires that I purchase the $350 Add-In Express. Is there a way I can do from INSIDE OUTLOOK without having to purchase anything else?
    Sunday, December 15, 2013 8:13 PM
  • Hello Michael,

    Note, the Outlook Object Model is common for all kind of add-ins (macros, shared, VSTO, ADX based). There is no need to use Add-in Express. Moreover, the C# and VB.NET source code listed in the blog post shows the way how you can use the AdvancedSearch method in a VSTO based add-in:

    C# and VSTO:

    string advancedSearchTag = "Our first advanced search in Outlook";
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    // ...
    private void RunAdvancedSearch(Outlook.Application Application, string wordInSubject)
    {
        string scope = "Inbox";
        string filter = "urn:schemas:mailheader:subject LIKE '%" + wordInSubject + "%'";
        Outlook.Search advancedSearch = null;
        Outlook.MAPIFolder folderInbox = null;
        Outlook.MAPIFolder folderSentMail = null;
        Outlook.NameSpace ns = null;
        try
        {
            ns = Application.GetNamespace("MAPI");
            folderInbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            folderSentMail = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
            scope = "'" + folderInbox.FolderPath + "','" + 
                                                       folderSentMail.FolderPath + "'";
            advancedSearch = Application.AdvancedSearch(
                                                scope, filter, true, advancedSearchTag);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "An eexception is thrown");
        }
        finally
        {
            if (advancedSearch != null) Marshal.ReleaseComObject(advancedSearch);
            if (folderSentMail != null) Marshal.ReleaseComObject(folderSentMail);
            if (folderInbox != null) Marshal.ReleaseComObject(folderInbox);
            if (ns != null) Marshal.ReleaseComObject(ns);
        }
    }
     
    void Application_AdvancedSearchComplete(Outlook.Search SearchObject)
    {            
        Outlook.Results advancedSearchResults = null;
        Outlook.MailItem resultItem = null;
        System.Text.StringBuilder strBuilder = null;
        try
        {
            if (SearchObject.Tag == advancedSearchTag)
            {
                advancedSearchResults = SearchObject.Results;
                if (advancedSearchResults.Count > 0)
                {
                    string[] version = Application.Version.Split('.');
                    int hostMajorVersion = Convert.ToInt32(version[0]);
                    if (hostMajorVersion > 10)
                    {
                        object folder = SearchObject.GetType().InvokeMember("Save",
                                                System.Reflection.BindingFlags.Instance |
                                                System.Reflection.BindingFlags.InvokeMethod |
                                                System.Reflection.BindingFlags.Public,
                                                null, SearchObject, 
                                                new object[] { advancedSearchTag });
     
                    }
                    else
                    {
                        strBuilder = new System.Text.StringBuilder();
                        strBuilder.AppendLine("Number of items found: " + 
                                               advancedSearchResults.Count.ToString());
                        for (int i = 1; i < = advancedSearchResults.Count; i++)
                        {
                            resultItem = advancedSearchResults[i] as Outlook.MailItem;
                            if (resultItem != null)
                            {
                                strBuilder.Append("#" + i.ToString());
                                strBuilder.Append(" Subject: " + resultItem.Subject);
                                strBuilder.Append(" \t To: " + resultItem.To);
                                strBuilder.AppendLine(" \t Importance: " + 
                                                       resultItem.Importance.ToString());
                                Marshal.ReleaseComObject(resultItem);
                            }
                        }
                        if (strBuilder.Length > 0)
                            System.Diagnostics.Debug.WriteLine(strBuilder.ToString());
                        else
                            System.Diagnostics.Debug.WriteLine(
                                                      "There are no Mail items found.");
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("There are no items found.");
                }
           }
       }
       catch (Exception ex)
       {
           MessageBox.Show(ex.Message, "An exception is occured");
       }
       finally
       {
           if (resultItem != null) Marshal.ReleaseComObject(resultItem);
           if (advancedSearchResults != null) 
               Marshal.ReleaseComObject(advancedSearchResults);
       }
    }

    VB.NET and VSTO:

    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    ' ...
    Dim advancedSearchTag As String = "Our first advanced search in Outlook"
     
    Private Sub RunAdvancedSearch(Application As Outlook.Application, wordInSubject As String)
        Dim scope As String = "Inbox"
        Dim filter As String = "urn:schemas:mailheader:subject LIKE '%" + wordInSubject + "%'"
        Dim advancedSearch As Outlook.Search = Nothing
        Dim folderInbox As Outlook.MAPIFolder = Nothing
        Dim folderSentMail As Outlook.MAPIFolder = Nothing
        Dim ns As Outlook.NameSpace = Nothing
        Try
            ns = Application.GetNamespace("MAPI")
            folderInbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
            folderSentMail = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail)
            scope = "'" + folderInbox.FolderPath + "','" + folderSentMail.FolderPath + "'"
            advancedSearch = Application.AdvancedSearch(scope, filter, True, advancedSearchTag)
        Catch ex As Exception
            MessageBox.Show(ex.Message, "An eexception is thrown")
        Finally
            If Not IsNothing(advancedSearch) Then Marshal.ReleaseComObject(advancedSearch)
            If Not IsNothing(folderSentMail) Then Marshal.ReleaseComObject(folderSentMail)
            If Not IsNothing(folderInbox) Then Marshal.ReleaseComObject(folderInbox)
            If Not IsNothing(ns) Then Marshal.ReleaseComObject(ns)
        End Try
    End Sub
     
    Private Sub adxOutlookEvents_AdvancedSearchComplete(SearchObject As Outlook.Search) 
                                              Handles Application.AdvancedSearchComplete
        Dim advancedSearchResults As Outlook.Results = Nothing
        Dim resultItem As Outlook.MailItem = Nothing
        Dim strBuilder As System.Text.StringBuilder = Nothing
        Try
            If (SearchObject.Tag = advancedSearchTag) Then
                advancedSearchResults = SearchObject.Results
                If (advancedSearchResults.Count > 0) Then
                    Dim version As String() = Application.Version.Split(".")
                    Dim hostMajorVersion As Integer = Convert.ToInt32(version(0))
                    If (hostMajorVersion > 10) Then
                        Dim folder As Object = SearchObject.GetType().InvokeMember("Save",
                                                 System.Reflection.BindingFlags.Instance Or
                                                 System.Reflection.BindingFlags.InvokeMethod Or 
                                                 System.Reflection.BindingFlags.Public,
                                                 Nothing, SearchObject, 
                                                 New [Object]() {advancedSearchTag})
                    Else
                        strBuilder = New System.Text.StringBuilder()
                        strBuilder.AppendLine("Number of items found: " + 
                                               advancedSearchResults.Count.ToString())
                        For i As Integer = 1 To advancedSearchResults.Count Step 1
                            resultItem = CType(advancedSearchResults(i), Outlook.MailItem)
                            If Not IsNothing(resultItem) Then
                                strBuilder.Append("#" + i.ToString())
                                strBuilder.Append(" Subject: " + resultItem.Subject)
                                strBuilder.Append(" To: " + resultItem.To)
                                strBuilder.AppendLine(" Importance: " + 
                                                        resultItem.Importance.ToString())
                                Marshal.ReleaseComObject(resultItem)
                            End If
                        Next
                        If (strBuilder.Length > 0) Then
                            System.Diagnostics.Debug.WriteLine(strBuilder.ToString())
                        Else
                            System.Diagnostics.Debug.WriteLine( _
                                                    "There are no Mail items found.")
                        End If
                    End If
                Else
                    System.Diagnostics.Debug.WriteLine("There are no items found.")
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "An exception is occured")
        Finally
            If Not IsNothing(resultItem) Then Marshal.ReleaseComObject(resultItem)
            If Not IsNothing(advancedSearchResults) Then 
                Marshal.ReleaseComObject(advancedSearchResults)
            End If
        End Try
    End Sub
    You can use the same code for VBA macros. Why do you need to purchase something else?


    Monday, December 16, 2013 6:37 AM
  • Thank-you, I currently have Visual Basic 2010 Express installed on my computer. Is there a link to how to make an add-in? Do I need to install something else, like VSTO (Visual Studio Tools for Office), or download another program in order to accomplish this? If I do does that program require that I purchase anything?
    Monday, December 16, 2013 6:49 AM
  • Hi Michael,

    You need Visual Studio 2010 Professional, Premium or Ultimate to be able to develop VSTO add-ins. As a workaround, you can develop a VBA macro.

    Monday, December 16, 2013 6:56 AM
  • Hi Eugene,

    There's a hole in my bucket. I notice that When I try to do an Advanced Search from the GUI using the form, it doesn't allow me to search multiple accounts. I am receiving an error when I try to run my code in VBA. My post from earlier:

    Thank-you, I have gotten closer.

    I had to modify your code a little as VBA doesn't like the += switch. The code works up until it tries to search. It gives me a run time error of '-2147221241 (80040107) The attempted operation failed. An object could not be found.'

    Dim ns As Outlook.NameSpace
    Dim sts As Outlook.Stores, st As Outlook.Store
    Dim folders As String
    Dim i As Integer
    Dim sch As Outlook.Search
    
        Set ns = Outlook.GetNamespace("MAPI")
        Set sts = ns.Stores
        
        folders = folders & "'"
        
        For Each st In sts
    
            i = i + 1
    
            folders = folders & st.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderJunk).FolderPath
            
            'Add quotes and commas
            If i < sts.Count Then
    
                folders = folders & "','"
                
            Else
            
                folders = folders & "'"
    
            End If
    
        Next
        
        Set sch = Outlook.AdvancedSearch(folders)

    Monday, December 16, 2013 7:17 AM
  • Michael,

    Did you have a chance to look at the steps I described above?

    I have already replied to this post:

    • The AdvancedSearch method takes four parameters. Did you try to specify all of them?   In the sample code above you specified only one argument.   
    • Do you handle the AdvancedSearchComplete event of the Application class?    To get results of the search engine you need to handle the AdvancedSearchComplete event. Did you subscribe to the event?

    Monday, December 16, 2013 7:23 AM
  • Why doesn't Microsoft just implement a Combined Inbox, Combined Junk, etc. into Outlook? I understand that their main market is businesses and corporations that would only need one mailbox, one account. But what about the common consumer who may have more than one email account or an employee who has one personal account and uses Outlook at home to check their work email as well? 
    Monday, December 16, 2013 7:27 AM
  • Thank-you for your non-help. This article has been given to me at least 5 times, yet it doesn't say ANYTHING about VBA. Did you even look at my code, or is that just a standard answer you have to anyone who asks this question?
    Monday, December 16, 2013 7:36 AM
  • Michael,

    You are right. Advanced Search doesn't allow searching in different stores (*.pst). It looks like you need to run the search procedure each time for a separate store.

    > Why doesn't Microsoft just implement a Combined Inbox, Combined Junk, etc. into Outlook?

    Do you want to combine business and private mailboxes? I suppose it is not as it should be. Each mailbox has its own settings/search folders. Moreover, mails should be filtered differently.

    Monday, December 16, 2013 7:36 AM
  • Actually, I did, even proposed to handle the AdvancedSearchComplete event to get the search results and specify all four arguments.

    Note, the link the MSDN page for AdvancedSearch method was provided many times in my previous posts. It does provide a sample VBA code.


    Monday, December 16, 2013 7:40 AM
  • Currently I do not combine business and personal accounts. But One of the reasons why I have waited so long to switch from Windows Live Mail to Outlook 2013 is because of the Combined views in WLM. It is just so convenient to be able to view all of the emails in the Inbox of every account you have instead of having to switch back and forth between accounts just to read your emails. Oh, I just received an email but I missed the pop-up, now I have to view each account one-by-one to find the new email. Or with a combined view the new email is right there at the top of the list waiting for me.
    Monday, December 16, 2013 7:48 AM
  • Michael,

    You can configure a rule in Outlook to move all incoming e-mails into a single folder. Is that you are looking for?

    Monday, December 16, 2013 7:55 AM
  • Wouldn't that move the emails out of the account they originated from into a single pst? Then when I am away from my computer and try to log in to my email account from their website, the emails I want to see won't be there because now they are stored on my PC and that will eat up the memory of my PC. I want to keep the emails where they are and just view the emails as a single list.
    Monday, December 16, 2013 8:02 AM
  • Michael,

    This question is not related to the initial one. That is why I would recommend discussing such questions in the Outlook IT Pro forum thread. This thread is for developers.

    Monday, December 16, 2013 8:05 AM
  • My original question:
    -----------------------------------------------------------------------------------------------------
    I am finally making the switch from Windows Live Mail to Outlook 2013. The main reason I kept WLM is because of the included Default Search folders such as "All Inbox" "All Junk" "All Mail" etc. I have found some articles to help search in a particular folder over multiple accounts. The problem I'm running into is that Outlook.com has a junk folder named "Junk E-mail" and Google has its junk named "Spam"

    Here is my code:

    Sub UnifiedJunkbox()
    Dim myOlApp As New Outlook.Application
    txtSearch = "folder: 'Junk E-Mail','Spam'"
    myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders
    Set myOlApp = Nothing
    End Sub

    How can I set up a search filter to view All junk messages from All accounts? I am not going to move or copy every single message to common folders just to accomplish this, that is redundant and ridiculous; I want to keep the messages where they belong and just be able to see a combined view.

    -----------------------------------------------------------------------------------------------------

    It was my intent all along to have a combined view of the Junk folders from all of my accounts and is totally related. I will try to post to the suggested form, but at least now when someone else tries to search for how to do this, they will have at least something to go with.



    Monday, December 16, 2013 8:11 AM
  • To anyone who wants to know more, at the recommendation of Eugene, I have continued the discussion in the Outlook IT Pro forum and you can find it here: http://social.technet.microsoft.com/Forums/office/en-US/7aec5460-ebdb-4e3d-b481-0a29355fdea3/macro-to-search-all-junk-from-multiple-imappop3exchange-accounts?forum=outlook
    Monday, December 16, 2013 6:32 PM