locked
Outlook Search Subfolder RRS feed

  • Question

  • Hi guys, got this code below from: https://docs.microsoft.com/en-us/office/vba/outlook/how-to/search-and-filter/search-the-inbox-for-items-with-subject-containing-office

    I tried to modified it and put the path of the folder but it has a run-time error on the search portion, any ideas how to modify this?

    The construct filter is for Subject:  'Construct filter. 0x0037001E represents Subject

    If I will search for the email body what would be the filter?

    Thanks for any input.

    Sub TestSearchWithTable()
        Dim oSearch As Search
        Dim oTable As table
        Dim strQuery As String
        Dim oRow As row
             
        blnSearchComp = False
         
        'Construct filter. 0x0037001E represents Subject
        strQuery = _
            "http://schemas.microsoft.com/mapi/proptag/0x0037001E" & _
            " ci_phrasematch 'assigned to'"
         
        'Do search
        Set oSearch = _
            Application.AdvancedSearch("\\my.email@mydomain.com\Inbox\sales-today", strQuery, False, "Test")
        While blnSearchComp = False
            DoEvents
        Wend
     
        'Obtain Table
        Set oTable = oSearch.GetTable
         
        'Print Subject of each returned item
        Do Until oTable.EndOfTable
            Set oRow = oTable.GetNextRow
            Debug.Print oRow("Subject")
        Loop
    End Sub


    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.


    • Edited by cguan Tuesday, March 19, 2019 11:33 AM edit
    Tuesday, March 19, 2019 11:31 AM

All replies

  • Hi,

    Thanks for visiting our forum. Here we mainly focus on general issues about Outlook desktop client. Considering that your question is more related to VBA, it is suggested to post a new thread to the following MSDN forum for Outlook:

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=outlookdev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.


    Regards,

    Aidan Wang


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Wednesday, March 20, 2019 2:07 AM
  • Thanks, possible to move this thread to the said forum?

    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

    Wednesday, March 20, 2019 3:56 AM
  • Hi cguan,

    I’m afraid that I can’t move your thread to the MSDN forum directly.
    So it is suggested to post a new thread yourself. 

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=outlookdev

    Thanks for your understanding.


    Regards,

    Aidan Wang


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Wednesday, March 20, 2019 8:13 AM
  • Hi,
     
    Please remember to mark the replies as answers if they helped.
    And if you need further assistance on this, please feel free to post back.


    Regards,

    Aidan Wang


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, March 25, 2019 9:18 AM