我已经安装了Visual Studio 2017 Pro并且正在编写VSTO Outlook加载项。基本上我想在将新项目添加到已发送项目文件夹时执行代码。我一直在研究,显然这是最有效的方法,而不是在ItemSend事件上有代码。
我添加了各种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 :(得分: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