撰写电子邮件时触发

问题描述 投票:0回答:1

每次选择消息时都会执行此代码。我希望这个代码只有在我编写新的邮件/回复/转发时才能执行。

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

我想要实现的目标:当从特定帐户([email protected])撰写邮件时,在CC字段中添加收件人。

我是编程的菜鸟。

vba outlook
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.