2

我正在尝试编写一个宏,每当用户点击发送按钮时,它都会查看电子邮件的主题行。

但是我找不到任何收听该按钮的文档。现在我只是想让它在发送MsgBox电子邮件时发送带有主题的内容。有没有办法听(从 DOM 的角度思考)这个按钮并在点击时触发一个宏。

4

1 回答 1

4

正如悉达多所建议的:

我写了一个小演示,它检查一些条件来决定是否应该取消发送操作。这可以扩展到做其他事情,比如插入日期,将邮件保存到某个文件夹,......

Option Explicit

Private Sub Application_ItemSend(ByVal objItem As Object, Cancel As Boolean)
    Dim mi As MailItem

    If TypeName(objItem) = "MailItem" Then
        Set mi = objItem

        Debug.Print mi.Subject

        check Cancel, Trim(mi.Subject) <> "", "Subject is empty!"
        check Cancel, Not isRecipient(mi, "John@Doe.net"), _
              "John is on our embargo list!"
    End If
End Sub

Private Sub check(ByRef Cancel As Boolean, cond As Boolean, msg As String)
    If Not (Cancel Or cond) Then
        Cancel = (MsgBox(msg & vbCrLf & "Cancel send operation?", _
                         vbYesNoCancel, "Confirm?") <> vbNo)
    End If
End Sub

Private Function isRecipient(mi As MailItem, forbidden As String) As Boolean
    Dim ret As Boolean
    Dim rc As Recipient

    ret = False

    For Each rc In mi.recipients
        If StrComp(rc.Address, forbidden, vbTextCompare) = 0 Then
            ret = True
            Exit For
        End If
    Next

    isRecipient = ret
End Function
于 2013-04-16T20:05:33.233 回答