none
VBA: Search Outlook emails by Dynamic subject name RRS feed

  • Question

  • Hi,

    I am working on Task Organizer file that I use daily basis to update my tasks,  my reference is email subject of each raw, each time when I need to update raw with last status, I have to search on the this email manually.

    However, I started to work on VBA code that just click button on the same raw and with reference to subject name (B cell) it go to  find this subject related email in my inbox folder and find any unread emails then display, otherwise display last read email of the chain.

    CODE:

    Sub Test()

    Dim olApp As Outlook.Application
    Dim olNs As Namespace
    Dim Fldr As MAPIFolder
    Dim olMail As Variant
    Dim i As Integer

    Set olApp = New Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")
    Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
    i = 1

    For Each olMail In Fldr.Items
    If InStr(olMail.Subject, "Re: [Ext] Receipt of goods") <> 0 Then
    olMail.Display

    i = i + 1
    End If
    Next olMail
    End Sub

     Best Regards

    Muhanad

    Tuesday, December 17, 2019 12:14 AM