0

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
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Tennis
  • 137
  • 12

2 Answers2

1

Yes. Use Like operator:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If Item.Subject Like "Fees Due*" Or Item.Subject Like "Status Change*" Then
        If MsgBox("Do you want to continue sending the mail?", vbOKCancel) <> vbOK Then
            Cancel = True
        End If
    End If
End Sub

I added outer If ... End If, nothing else was changed.

miroxlav
  • 11,796
  • 5
  • 58
  • 99
0

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
0m3r
  • 12,286
  • 15
  • 35
  • 71
  • 1
    Perfect! Exactly what I was looking for. Thank you for going the extra mile to help. This has saved me from many headaches. – Tennis Aug 22 '17 at 20:53