I am working on Outlook VSTO Plugins to display a message on top of Current Opened Window. Such as I want to display a message to user when try to "Reply All" on certain conditions. On Email it is working fine but same is not working on Meeting.
Case Email - (Reply, Reply All, New)
It is working fine code as is follows.
'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
But the same code is not working on AppointmentItem. Code is as follows. Only changes I have done in Open event and Thread
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
I am getting error Unable to cast COM object type 'System._ComObject' to interface type 'Microsoft.VisualStudio.Tools.Office.Runtime.ICustomTaskPaneSite'. This operation faled because the QueryInterface call on teh COM component for the itnterface with IID{} failed due to the following error: No Such interface supported.
Environment: Visual Studio 2019 Office 2016