vbaoutlookoutlook-2016

How to display msgbox if subject contains string


The following Outlook macro works perfectly, However, I would like this MsgBox to only appear if the Subject is LIKE 'Fees Due%' OR Subject is LIKE' Status Change%'. Is this possible?

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If MsgBox("Do you want to continue sending the mail?", vbOKCancel) <> vbOK Then
        Cancel = True
    End If
End Sub

Solution

  • Should be

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
        Dim Subject As String
        Subject = Item.Subject
    
        If Subject Like "*Fees Due*" Or Subject Like "*Status Change*" Then
            If MsgBox("Do you want to continue sending the mail?", _
                       vbYesNo + vbQuestion + vbMsgBoxSetForeground, _
                                                   "Check Subject") = vbNo Then
                Cancel = True
            End If
    
        End If
    End Sub