S
Scott Lyon
I'm dealing with a strange problem. I've created a "shared add-in" for office
(in VB.NET 2005), part of which includes an integration for Microsoft Outlook
(2003). Part of that integration is adding an item to the Insert menu when
editing an e-mail that will allow it to add text to the e-mail being edited.
The add-in works just fine if I use the built-in Outlook editor for e-mails.
The problem comes up when I switch the editor in Outlook to use Microsoft
Word as the editor instead.
When I do so, I find that I either don't get the events at all (confirmed by
stepping through in debug mode), or I get the events exactly once (running
through without error), and not hit again, even if the user selects the
custom Insert option again and again.
To simplify things, I created a standalone add-in to demonstrate the
problem: this example will add an option to your Insert menu in Outlook (when
editing an e-mail) called Add Text, which will add "This is a test" to the
top of your e-mail.
If you run it with the Outlook editor, it works as expected. If you switch
to use Word as the editor, while the menu is there, every click on it goes
absolutely nowhere.
Any ideas?
Here's the only custom code I did after creating the add-in using the
"shared add-in" wizard and selecting only Outlook - this is my entire
Connect.vb module:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Imports Extensibility
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Microsoft.Office.Interop.Outlook
#Region " Read me for Add-in installation and setup information. "
' When run, the Add-in wizard prepared the registry for the Add-in.
' At a later time, if the Add-in becomes unavailable for reasons such as:
' 1) You moved this project to a computer other than which is was originally
created on.
' 2) You chose 'Yes' when presented with a message asking if you wish to
remove the Add-in.
' 3) Registry corruption.
' you will need to re-register the Add-in by building the $SAFEOBJNAME$Setup
project,
' right click the project in the Solution Explorer, then choose install.
#End Region
<GuidAttribute("C6754E2C-E204-48E5-B0F8-B58CFBF391CF"),
ProgIdAttribute("TestOutlookAddin.Connect")> _
Public Class Connect
Implements Extensibility.IDTExtensibility2
Const DROPDOWN_MENU As Integer = 10
Const MENU_BUTTON As Integer = 1
Dim applicationObject As Object
Dim addInInstance As Object
Private myItem As Inspector
Private WithEvents myItems As Inspectors
Private WithEvents _Item As Microsoft.Office.Interop.Outlook.MailItem
Private colCommandBars As CommandBars
Private cbbMenu As CommandBarPopup
Private WithEvents cbbAddText As CommandBarButton
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub
Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnStartupComplete
If applicationObject.name.ToString = "Outlook" Then
myItems = CType(applicationObject.Inspectors,
Microsoft.Office.Interop.Outlook.Inspectors)
End If
End Sub
Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnDisconnection
cbbAddText.Delete()
End Sub
Public Sub OnConnection(ByVal application As Object, ByVal connectMode As
Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As
System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
applicationObject = application
addInInstance = addInInst
End Sub
Private Sub myItems_NewInspector(ByVal Inspector As
Microsoft.Office.Interop.Outlook.Inspector) Handles myItems.NewInspector
myItem = Inspector
colCommandBars = myItem.CommandBars
If myItem.CurrentItem.Class =
Microsoft.Office.Interop.Outlook.OlObjectClass.olMail Then
_Item = myItem.CurrentItem
Else
Exit Sub
End If
cbbMenu = CType(colCommandBars.FindControl(Id:="30005"),
Microsoft.Office.Core.CommandBarPopup)
cbbAddText = CType(cbbMenu.Controls.Add(MENU_BUTTON),
Microsoft.Office.Core.CommandBarButton)
cbbAddText.Caption = "Add Text"
End Sub
Private Sub cbbAddText_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles cbbAddText.Click
_Item.HTMLBody = "<html><body>this is a test <p> " & _Item.HTMLBody &
"</body></html>"
_Item.Display()
End Sub
Private Sub _Item_Close(ByRef Cancel As Boolean) Handles _Item.Close
cbbAddText.Delete()
End Sub
End Class
(in VB.NET 2005), part of which includes an integration for Microsoft Outlook
(2003). Part of that integration is adding an item to the Insert menu when
editing an e-mail that will allow it to add text to the e-mail being edited.
The add-in works just fine if I use the built-in Outlook editor for e-mails.
The problem comes up when I switch the editor in Outlook to use Microsoft
Word as the editor instead.
When I do so, I find that I either don't get the events at all (confirmed by
stepping through in debug mode), or I get the events exactly once (running
through without error), and not hit again, even if the user selects the
custom Insert option again and again.
To simplify things, I created a standalone add-in to demonstrate the
problem: this example will add an option to your Insert menu in Outlook (when
editing an e-mail) called Add Text, which will add "This is a test" to the
top of your e-mail.
If you run it with the Outlook editor, it works as expected. If you switch
to use Word as the editor, while the menu is there, every click on it goes
absolutely nowhere.
Any ideas?
Here's the only custom code I did after creating the add-in using the
"shared add-in" wizard and selecting only Outlook - this is my entire
Connect.vb module:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Imports Extensibility
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Microsoft.Office.Interop.Outlook
#Region " Read me for Add-in installation and setup information. "
' When run, the Add-in wizard prepared the registry for the Add-in.
' At a later time, if the Add-in becomes unavailable for reasons such as:
' 1) You moved this project to a computer other than which is was originally
created on.
' 2) You chose 'Yes' when presented with a message asking if you wish to
remove the Add-in.
' 3) Registry corruption.
' you will need to re-register the Add-in by building the $SAFEOBJNAME$Setup
project,
' right click the project in the Solution Explorer, then choose install.
#End Region
<GuidAttribute("C6754E2C-E204-48E5-B0F8-B58CFBF391CF"),
ProgIdAttribute("TestOutlookAddin.Connect")> _
Public Class Connect
Implements Extensibility.IDTExtensibility2
Const DROPDOWN_MENU As Integer = 10
Const MENU_BUTTON As Integer = 1
Dim applicationObject As Object
Dim addInInstance As Object
Private myItem As Inspector
Private WithEvents myItems As Inspectors
Private WithEvents _Item As Microsoft.Office.Interop.Outlook.MailItem
Private colCommandBars As CommandBars
Private cbbMenu As CommandBarPopup
Private WithEvents cbbAddText As CommandBarButton
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub
Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnStartupComplete
If applicationObject.name.ToString = "Outlook" Then
myItems = CType(applicationObject.Inspectors,
Microsoft.Office.Interop.Outlook.Inspectors)
End If
End Sub
Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnDisconnection
cbbAddText.Delete()
End Sub
Public Sub OnConnection(ByVal application As Object, ByVal connectMode As
Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As
System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
applicationObject = application
addInInstance = addInInst
End Sub
Private Sub myItems_NewInspector(ByVal Inspector As
Microsoft.Office.Interop.Outlook.Inspector) Handles myItems.NewInspector
myItem = Inspector
colCommandBars = myItem.CommandBars
If myItem.CurrentItem.Class =
Microsoft.Office.Interop.Outlook.OlObjectClass.olMail Then
_Item = myItem.CurrentItem
Else
Exit Sub
End If
cbbMenu = CType(colCommandBars.FindControl(Id:="30005"),
Microsoft.Office.Core.CommandBarPopup)
cbbAddText = CType(cbbMenu.Controls.Add(MENU_BUTTON),
Microsoft.Office.Core.CommandBarButton)
cbbAddText.Caption = "Add Text"
End Sub
Private Sub cbbAddText_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles cbbAddText.Click
_Item.HTMLBody = "<html><body>this is a test <p> " & _Item.HTMLBody &
"</body></html>"
_Item.Display()
End Sub
Private Sub _Item_Close(ByRef Cancel As Boolean) Handles _Item.Close
cbbAddText.Delete()
End Sub
End Class