【发布时间】:2021-08-26 21:52:00
【问题描述】:
我正在开发 Outlook VSTO 插件以在当前打开的窗口顶部显示一条消息。例如,我想在某些条件下尝试“全部回复”时向用户显示一条消息。在电子邮件上它工作正常,但在会议上同样不工作。
案例电子邮件 -(回复、全部回复、新建)
运行良好的代码如下。
'Starup Event to initialize control objects
Private Sub ThisAddIn_Startup() Handles Me.Startup
Try
'Insitialize outlook inspector.
inspectors = Globals.ThisAddIn.Application.Inspectors
'Create new inspector
AddHandler inspectors.NewInspector, AddressOf inspectors_NewInspector
Catch ex As System.Exception
'MessageBox.Show(ex.StackTrace)
End Try
End Sub
Sub inspectors_NewInspector(inspector As Microsoft.Office.Interop.Outlook.Inspector)
Try
subInspector = inspector
Dim mailItem As Outlook.MailItem
mailItem = DirectCast(inspector.CurrentItem, Outlook.MailItem)
'AddHandler mailItem.Open, AddressOf explorer_onOpen
Catch ex As System.Exception
End Try
End Sub
Private Sub explorer_onOpen()
'I am using Thread to wait few seconds until New Email Windows open.
'Else message message bar display on the windows which opened and on top. and
' New/Reply email windows takes some time to appear.
Dim thread As New Thread(AddressOf MyBackgroundThread)
thread.IsBackground = True
thread.Start()
End Sub
Private Sub MyBackgroundThread()
Try
'Pause code for 2.5 seconds
Thread.Sleep(2500)
MessageBox.Show("Threading")
_obj = New UserControl2
Dim _pane1 = Globals.ThisAddIn.CustomTaskPanes.Add(_obj,"Test",Globals.ThisAddIn.Application.ActiveWindow)
_pane1.Visible=True
Catch ex As System.Exception
MessageBox.Show(ex.Message)
End Try
End Sub
但相同的代码不适用于 AppointmentItem。代码如下。只有我在 Open 事件和线程中所做的更改
Sub inspectors_NewInspector(inspector As Microsoft.Office.Interop.Outlook.Inspector)
Try
subInspector = inspector
Dim appouitmentItem As Outlook.AppointmentItem
appouitmentItem = DirectCast(inspector.CurrentItem, Outlook.AppointmentItem)
AddHandler appouitmentItem.Open, AddressOf explorer_onOpen
Catch ex As System.Exception
End Try
End Sub
Private Sub explorer_onOpen()
'Thread to display warning message after few seconds
MessageBox.Show("Thread to display warning message after few seconds")
Dim thread As New Thread(AddressOf MyBackgroundThread)
thread.IsBackground = True
thread.Start()
End Sub
Private Sub MyBackgroundThread()
Try
'Pause code for 2.5 seconds
Thread.Sleep(2500)
MessageBox.Show("Threading")
_obj = New UserControl2
Dim _pane1 = Globals.ThisAddIn.CustomTaskPanes.Add(_obj,"Test",Globals.ThisAddIn.Application.ActiveWindow)
_pane1.Visible=True
Catch ex As System.Exception
MessageBox.Show(ex.Message)
End Try
End Sub
我收到错误 无法将 COM 对象类型“System._ComObject”转换为接口类型“Microsoft.VisualStudio.Tools.Office.Runtime.ICustomTaskPaneSite”。此操作失败,因为 IID{} 接口的 COM 组件上的 QueryInterface 调用失败,原因是以下错误:不支持此类接口。
环境: 视觉工作室 2019 办公室 2016
【问题讨论】:
标签: outlook vsto outlook-addin