2017-05-08 134 views
0

我已經安裝了Visual Studio 2017 Pro,並且正在編寫VSTO Outlook加載項。實質上,我想在將新項目添加到已發送項目文件夾時執行代碼。我一直在研究,顯然這是這樣做的最有效的方式,而不是在ItemSend事件上有代碼。Visual Basic移動Outlook將項目發送到其他文件夾

我已經添加了各種MsgBox命令,所以我可以看到各個位實際上正在運行,但由於某種原因,ItemAdd事件似乎沒有被觸發。我的代碼如下:

Public Class ThisAddIn 
    Public WithEvents myOlItems As Outlook.Items 

    Private Sub ThisAddIn_Startup() Handles Me.Startup 
     MsgBox("Initliasing add-in") 
     AddIn_Init() 
    End Sub 

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown 

    End Sub 

    Private Sub AddIn_Init() 
     myOlItems = Application.GetNamespace("MAPI").GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail).Items 
     MsgBox("We are ready!") 
    End Sub 

    Private Sub myOlItems_ItemAdd(ByVal Item As Object) 
     MsgBox("You sent an email from " & Item.SenderEmailAddress) 
    End Sub 

End Class 

我想我靠近它的工作,但我還沒有應用 - 任何指針十分感激地接受。

+0

您是否嘗試添加句柄myOlItems.ItemAdd? –

+0

嗨 - 這不是什麼私人小組myOlItems_ItemAdd(ByVal項目爲對象)嗎? –

+0

對不起,我不明白 - 一旦我使用Visual Studio下拉菜單,一切都變得清晰:) –

回答

0

最終的代碼現在正在工作 - 謝謝!

Public Class ThisAddIn 
    Public WithEvents myOlItems As Outlook.Items 

    Private Sub ThisAddIn_Startup() Handles Me.Startup 
     MsgBox("Initliasing add-in") 
     AddIn_Init() 
    End Sub 

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown 

    End Sub 

    Private Sub AddIn_Init() 
     myOlItems = Application.GetNamespace("MAPI").GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail).Items 

     MsgBox("We are ready!") 
    End Sub 

    Private Sub myOlItems_ItemAdd(Item As Object) Handles myOlItems.ItemAdd 
     MsgBox("You sent an email from " & Item.SenderEmailAddress) 
    End Sub 
End Class 
相關問題