在Outlook中发送电子邮件时,有一个名为MailItemClass
的VBA类具有event。我找不到这个用于VB.NET。我查看了documentation,但我在MAPI
找不到它。
(我可以从VB.NET调用VBA吗?)
答案 0 :(得分:2)
您是否正在制作Outlook加载项?在发送项目之前会引发一个名为Application.ItemSend的事件。我刚刚启动了VS2010,创建了一个Outlook 2007加载项类型的新项目,该项目仅包含以下代码,当我单击“从Outlook发送”时,Application_ItemSend
按预期触发。
Public Class ThisAddIn
Private Sub ThisAddIn_Startup() Handles Me.Startup
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
End Sub
Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles Application.ItemSend
System.Windows.Forms.MessageBox.Show("Hi")
End Sub
End Class
修改强>
如果你正在制作一个WinForms应用程序,你使用相同的方法,但你“看到”它有点不同。可能有点令人困惑的是,事件是在应用程序级别引发的,而不是从邮件项本身引发的。
Public Class Form1
''//Holds a reference to our mail application
Private WithEvents OA As Microsoft.Office.Interop.Outlook.Application
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
''//Either launches Outlook or snaps to the current running one
OA = New Microsoft.Office.Interop.Outlook.Application()
End Sub
Private Sub OA_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles OA.ItemSend
MessageBox.Show("Hello")
End Sub
End Class
答案 1 :(得分:0)