撰写电子邮件时触发

时间:2017-08-30 13:24:32

标签: vba outlook

每次选择邮件时都会执行此代码。我希望只有在撰写新邮件/回复/转发时才会执行此代码。

Private Sub Application_ItemLoad(ByVal Item As Object)
    Dim oAccount As Outlook.Explorer
    If TypeName(Item) = "MailItem" Then
        MsgBox ("this is mail")
        Set oAccount = Application.ActiveExplorer   
        MsgBox (oAccount.CurrentFolder.FolderPath)
    End If
End Sub

我想要实现的目标:在撰写来自特定帐户(account@mail.com)的邮件时,在CC字段中添加收件人。

我是编程中的菜鸟。

1 个答案:

答案 0 :(得分:0)

您可以测试MailItem.Sent属性,以确定是撰写邮件还是阅读收到的邮件。

Private Sub Application_ItemLoad(ByVal Item As Object)

    Dim oAccount As Outlook.Explorer

    If TypeName(Item) = "MailItem" Then

        If item.Sent Then
            MsgBox "Not for processing"
        Else
            MsgBox "Processing this mail"
            Set oAccount = Application.ActiveExplorer   
            MsgBox (oAccount.CurrentFolder.FolderPath)
        End If

    End If

End Sub