lundi 25 septembre 2017

Programming VBA Checkbox on Outlook

I have ZERO experience with VBA, so I thought why not ask you, before I put hours and hours into research, reading the documentation and experimenting.

I know how to do a popup message, which appears every time when I put a email address into the FROM, CC and BCC, to warn me that I am sending an email to another domain than, let's say: @example.com.

But how do I create a checkbox in my popup message for every external domain in the FORM, CC and BCC field, that has to be ticked to send the emails to this addresses?

I am using the code from user matho:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim recips As Outlook.Recipients
    Dim recip As Outlook.Recipient
    Dim pa As Outlook.PropertyAccessor
    Dim prompt As String
    Dim strMsg As String

    Const PR_SMTP_ADDRESS As String = "http://ift.tt/1tb7qQt"

    Set recips = Item.Recipients
    For Each recip In recips
        Set pa = recip.PropertyAccessor
        If InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@example.com") = 0 Then
            strMsg = strMsg & "   " & pa.GetProperty(PR_SMTP_ADDRESS) & vbNewLine
        End If
    Next

    If strMsg <> "" Then
        prompt = "This email will be sent outside of example.com to:" & vbNewLine & strMsg & "Do you want to proceed?"
        If MsgBox(prompt, vbYesNo + vbExclamation + vbMsgBoxSetForeground, "Check Address") = vbNo Then
            Cancel = True
        End If
    End If
End Sub




Aucun commentaire:

Enregistrer un commentaire