none
Create a Search Folder for All Unreplied Emails in Shared Mailbox RRS feed

  • Question

  • Hi All,

    I am trying to create a macro to identify unreplied email in Shared Mailbox folder for last 1 month. For Example, if we have 200 emails in Shared mailbox - Inbox then how can we identify on which emails has been replied or which is not. I do have a coding however, that coding is working only on personal mailbox (below is the Coding), Not on the shared mailbox. Please help.

    For Personal Mailbox coding is :

    Sub CreateSearchFolder_AllNotRepliedEmails()
        Dim strScope As String
        Dim strRepliedProperty As String
        Dim strFilter As String
        Dim objSearch As Outlook.Search

        'Specify the folders to be searched
        'Here we use Inbox folder for an example
        strScope = "'" & Application.Session.GetDefaultFolder(olFolderInbox).FolderPath & "'"

        'Search filter
        strRepliedProperty = "http://schemas.microsoft.com/mapi/proptag/0x10810003"
        strFilter = Chr(34) & strRepliedProperty & Chr(34) & " <> 102" & "AND" & Chr(34) & strRepliedProperty & Chr(34) & " <> 103"
        Set objSearch = Outlook.Application.AdvancedSearch(Scope:=strScope, Filter:=strFilter, SearchSubFolders:=True, Tag:="SearchFolder")

        'Save the search folder
        objSearch.Save ("Not Replied Emails")
        MsgBox "Search folder is created successfully!", vbInformation + vbOKOnly, "Search Folder"
    End Sub


    Tuesday, June 26, 2018 3:23 PM

Answers

  • Are you not sure how to add criteria for the sender name and/or date range? You might want to close this thread and start a new one.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, June 28, 2018 4:18 PM

All replies

  • Hi Ankit,

    Thanks for visiting our forum. Then here we mainly focus on general issues about Outlook client. Since your query is related to using code in Outlook, I'll move your thread to the dedicated MSDN forum for Outlook for better response:

    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,

    Yuki Sun


    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, June 27, 2018 2:18 AM
  • You would need to use Application.Session.GetSharedDefaultFolder instead of GetDefaultFolder - create a Recipient objects using Application.Session.CreateRecipient and pass it to  GetSharedDefaultFolder. The rest of your code can stay the same.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, June 27, 2018 2:09 PM
  • Hi All,

    I am trying to create a macro to identify unreplied email in Shared Mailbox folder for last 1 month. For Example, if we have 200 emails in Shared mailbox - Inbox then how can we identify on which emails has been replied or which is not. I do have a coding however, that coding is working only on personal mailbox (below is the Coding), Not on the shared mailbox. Please help.

    For Personal Mailbox coding is :

    Sub CreateSearchFolder_AllNotRepliedEmails()
        Dim strScope As String
        Dim strRepliedProperty As String
        Dim strFilter As String
        Dim objSearch As Outlook.Search

        'Specify the folders to be searched
        'Here we use Inbox folder for an example
        strScope = "'" & Application.Session.GetDefaultFolder(olFolderInbox).FolderPath & "'"

        'Search filter
        strRepliedProperty = "http://schemas.microsoft.com/mapi/proptag/0x10810003"
        strFilter = Chr(34) & strRepliedProperty & Chr(34) & " <> 102" & "AND" & Chr(34) & strRepliedProperty & Chr(34) & " <> 103"
        Set objSearch = Outlook.Application.AdvancedSearch(Scope:=strScope, Filter:=strFilter, SearchSubFolders:=True, Tag:="SearchFolder")

        'Save the search folder
        objSearch.Save ("Not Replied Emails")
        MsgBox "Search folder is created successfully!", vbInformation + vbOKOnly, "Search Folder"
    End Sub

    Your help would be highly appreciated.

    Thanks

    Ankit

    Wednesday, June 27, 2018 2:10 PM
  • Hi Dmitry,

    Thank you so much for your response.

    I am trying to modify it as per your suggestion. However, I am unable to do it. Could you please help me to modify it.

    I really appreciate your help.

    Have a great day ahead.

    Thanks

    Ankit

    Wednesday, June 27, 2018 2:17 PM
  • What have you tried? If it does notrun, what is the error?

    Relace the line

    strScope = "'" & Application.Session.GetDefaultFolder(olFolderInbox).FolderPath & "'"

    with

    dim objFolder As Oulook.MAPIFolder

    dim objRecip As Outlook.Recipient

    objRecip = Application.Session.CreateRecipient("The mailbox name") set objFolder = Application.Session.GetSharedDefaultFolder(objRecip, olFolderInbox) strScope = "'" & objFolder.FlderPath & "'"



    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Wednesday, June 27, 2018 2:37 PM
  • See my reply at https://social.msdn.microsoft.com/Forums/en-US/4058e27e-46c3-44c5-a854-eece3d26998a/create-a-search-folder-for-all-unreplied-emails-in-shared-mailbox?forum=outlookdev

    Please do not multipost.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, June 27, 2018 2:41 PM
  • Which line gives you that error?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Wednesday, June 27, 2018 3:27 PM
  • Below is the Code which I modified, this code is working perfectly fine, however the filter is not working , it's giving all the emails which are replied or not replied from the same shared mailbox.

    I guess, we need to find out the replied property of Shared Mailbox. I guess, This property is for personal mailbox  objstrRepliedProperty = "http://schemas.microsoft.com/mapi/proptag/0x10810003"

    Option Explicit

    Public Sub CreateSearchFolder_AllNotRepliedEmails()
          Dim objstrScope As String
          Dim objstrRepliedProperty As String
          Dim objstrFilter As String
          Dim objSearch As Outlook.Search
          Dim objFolder As Outlook.MAPIFolder
          Dim objRecip As Outlook.Recipient

         

    Set objRecip = Application.Session.CreateRecipient("CODG Reporting")
     Set objFolder = Application.Session.GetSharedDefaultFolder(objRecip, olFolderInbox)
    'objstrScope = "'" & objFolder.FlderPath & "'"
    objstrScope = "'" & objFolder.FolderPath & "'"


         'Search filter
          objstrRepliedProperty = "http://schemas.microsoft.com/mapi/proptag/0x10810003"
          objstrFilter = Chr(34) & objstrRepliedProperty & Chr(34) & " <> 102" & "AND" & Chr(34) & objstrRepliedProperty & Chr(34) & " <> 103"
          Set objSearch = Outlook.Application.AdvancedSearch(Scope:=objstrScope, Filter:=objstrFilter, SearchSubFolders:=True, Tag:="SearchFolder")

         'Save the search folder
          objSearch.Save ("Not Replied Emails")
          MsgBox "Search folder is created successfully!", vbInformation + vbOKOnly, "Search Folder"
      End Sub



    Wednesday, June 27, 2018 3:45 PM
  • Change you filter to the following. You need to take into account messages with PR_LAST_VERB_EXECUTED property missing.

    objstrFilter = Chr(34) & objstrRepliedProperty & Chr(34) & " IS NULL " & " OR (" & _
                   Chr(34) & objstrRepliedProperty & Chr(34) & " <> 102" & "AND" & Chr(34) & objstrRepliedProperty & Chr(34) & " <> 103" & _
                   " ) "


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, June 27, 2018 5:06 PM
  • it's not working , getting the same result . Basically, I trying to find out if any email comes in shared mailbox and not replied from the shared mailbox then that emails should go to  "Not Replied Emails" folder.
    Wednesday, June 27, 2018 5:28 PM
  • Works fine here. Can you install OutlookSpy (http://www.dimastr.com/outspy/) and take a look at that search folder? Go to the folder in Outlook, click IMAPIFolder button, go to the GetSearchCriteria tab, copy the search criteria. Here is what I get:

    rt : RES_OR
      cRes : 2
      lpRes :
        rt : RES_AND
          cRes : 2
          lpRes :
            rt : RES_PROPERTY
            res.resProperty :
              relop : RELOP_NE
              ulPropTag : PR_LAST_VERB_EXECUTED (0x10810003)
              lpProp :
                ulPropTag : PR_LAST_VERB_EXECUTED (0x10810003)
                Value : 103
       
            rt : RES_PROPERTY
            res.resProperty :
              relop : RELOP_NE
              ulPropTag : PR_LAST_VERB_EXECUTED (0x10810003)
              lpProp :
                ulPropTag : PR_LAST_VERB_EXECUTED (0x10810003)
                Value : 102

        rt : RES_NOT
        res.resNot :
          lpRes :
            rt : RES_EXIST
            res.resExist :
              ulPropTag : PR_LAST_VERB_EXECUTED (0x10810003)


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, June 27, 2018 5:36 PM
  • Below is the Code , I am using and this code copying all the emails which are there in Shared Folder to "Not Replied Emails". Filter is not working.

    Option Explicit

    Public Sub CreateSearchFolder_AllNotRepliedEmails()
          Dim objstrScope As String
          Dim objstrRepliedProperty As String
          Dim objstrFilter As String
          Dim objSearch As Outlook.Search
          Dim objFolder As Outlook.MAPIFolder
          Dim objRecip As Outlook.Recipient

         

    Set objRecip = Application.Session.CreateRecipient("Mail box Name")
    Set objFolder = Application.Session.GetSharedDefaultFolder(objRecip, olFolderInbox)
    'objstrScope = "'" & objFolder.FlderPath & "'"
    objstrScope = "'" & objFolder.FolderPath & "'"


         'Search filter
          objstrRepliedProperty = "http://schemas.microsoft.com/mapi/proptag/0x10810003"
          objstrFilter = Chr(34) & objstrRepliedProperty & Chr(34) & " IS NULL " & " OR (" & _
                   Chr(34) & objstrRepliedProperty & Chr(34) & " <> 102" & "AND" & Chr(34) & objstrRepliedProperty & Chr(34) & " <> 103" & _
                   " ) "
          Set objSearch = Outlook.Application.AdvancedSearch(Scope:=objstrScope, Filter:=objstrFilter, SearchSubFolders:=True, Tag:="SearchFolder")

         'Save the search folder
          objSearch.Save ("Not Replied Emails")
          MsgBox "Search folder is created successfully!", vbInformation + vbOKOnly, "Search Folder"
      End Sub

     
    Wednesday, June 27, 2018 5:58 PM
  • So can you look at the search criteria with OutlookSpy?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, June 27, 2018 6:21 PM
  • Hi Dmitry,

    Thank you so much for helping me with this code. Above mentioned code is fine now. However, I am trying to modify this code if Sender (From Mailbox Name) <> Recipient Mailbox Name then this code should work. Also, When we run this code there should be Date Range filter from which date to which date you need to check if email has been not replied.

    Would really appreciate your inputs and modification in the current query.

    Thanks

    Ankit


    Thursday, June 28, 2018 12:43 AM
  • Are you not sure how to add criteria for the sender name and/or date range? You might want to close this thread and start a new one.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, June 28, 2018 4:18 PM
  • How to add more filters to this?

    Say for example if I want to add date and from or To address filters to this, how would I do it?

    Monday, July 27, 2020 1:33 PM