2017-08-30 126 views
0

每次選擇郵件時都會執行此代碼。我希望只有在撰寫新郵件/回覆/轉發時才能執行此代碼。撰寫電子郵件時觸發

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字段中添加收件人。

我是編程的noob。

+0

看到這個職位:https://stackoverflow.com/questions/44019988/setting-the-sender-email-address-according-to-the-recipient/44033922#44033922 –

+0

究竟是什麼,你正試圖實現? –

+0

感謝您的回覆傢伙。我試圖實現的是: 當有人試圖從特定帳戶([email protected])撰寫郵件時,自動需要在CC字段中添加收件人。如果從任何其他配置的電子郵件組成帳戶,應該沒有發生。如果這是有道理的...再次感謝這裏的任何幫助傢伙... – Art

回答

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 
相關問題