我试图在邮件项目打开时放入我已添加到FormRegion的文本框。文本框存在于项目中,但是当尝试将类别分配给文本框时,由于Formregion1为null,因此获取空引用异常。
Imports Microsoft.Office.Interop.Outlook
Public Class ThisAddIn
Private WithEvents inspectors As Outlook.Inspectors
Private Sub ThisAddIn_Startup() Handles Me.Startup
inspectors = Me.Application.Inspectors
End Sub
Private Sub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles inspectors.NewInspector
Dim mailItem As Outlook.MailItem = TryCast(Inspector.CurrentItem, Outlook.MailItem)
Dim mCat As String
Dim formRegions As WindowFormRegionCollection = Globals.FormRegions(Inspector)
mCat = mailItem.Categories
formRegions.FormRegion1.TextBox1.Text = mCat
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
End Sub
End Class
答案 0 :(得分:0)
很可能在NewInspector
事件被触发时,没有为检查器窗口创建表单区域。相反,我建议处理Inspector类的Activate事件,您可以在其中执行相同的操作。您可能会发现MSDN中的Creating Outlook Form Regions部分很有帮助。