imports Extensibility Imports System.Runtime.InteropServices Imports Microsoft.Office.Core Read me for Add-in installation and setup information.#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("E8CB3356-99C5-40A0-9169-C39D795E13D4"), ProgIdAttribute("MyAddin2.Connect")> _ PublicClass ConnectClass Connect Implements Extensibility.IDTExtensibility2 DimWithEvents CBtnbar As CommandBarButton DimWithEvents CBtnCG As CommandBarButton Dim applicationObject AsObject Dim addInInstance AsObject PublicSub OnBeginShutdown()Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown OnErrorResumeNext ' Notify the user you are shutting down, and delete the button. CBtnbar.Delete() CBtnbar =Nothing CBtnCG.Delete() CBtnCG =Nothing ' MsgBox("delete") End Sub PublicSub OnAddInsUpdate()Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate ' End Sub PublicSub OnStartupComplete()Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete Dim oCommandBars As CommandBars Dim oStandardBar As CommandBar Dim cmbMenu As CommandBar Dim ctlPopup As CommandBarPopup Dim applicationType As System.Type Const m_sMenuCaption AsString="Testing Addin" Const m_sMenuTag AsString="OutlookAddinTesting" Const m_sCmdCaption AsString="Configuration" Const m_sCmdTag AsString="OutlookAddinConfigTesting" Dim strtype AsString= applicationObject.name.ToString() OnErrorResumeNext If strtype ="Outlook"Then cmbMenu = applicationObject.ActiveExplorer.CommandBars("Tools") ctlPopup = cmbMenu.FindControl(MsoControlType.msoControlPopup, System.Type.Missing, m_sMenuTag, True, True) If ctlPopup IsNothingThen ctlPopup = cmbMenu.Controls.Add(Type:=MsoControlType.msoControlPopup, Temporary:=True, Before:=1) With ctlPopup .Tag = m_sMenuTag .Caption = m_sMenuCaption CBtnCG = .Controls.Add(Type:=MsoControlType.msoControlButton, Temporary:=True, Before:=1) CBtnCG.Caption = m_sCmdCaption CBtnCG.Tag = m_sCmdTag CBtnCG.Enabled =True EndWith EndIf EndIf ' Set up a custom button on the "Standard" command bar. oCommandBars = applicationObject.CommandBars If oCommandBars IsNothingThen ' Outlook has the CommandBars collection on the Explorer object. oCommandBars = applicationObject.ActiveExplorer.CommandBars EndIf oStandardBar = oCommandBars.Item("Standard") If oStandardBar IsNothingThen ' Access names its main toolbar Database. oStandardBar = oCommandBars.Item("Database") EndIf ' oStandardBar.Reset() ' In case the button was not deleted, use the exiting one. CBtnbar = oStandardBar.Controls.Item("Testing CommandbarControl") If CBtnbar IsNothingThen CBtnbar = oStandardBar.Controls.Add(1) With CBtnbar .Caption ="Testing CommandbarControl" .Style = MsoButtonStyle.msoButtonCaption ' The following items are optional, but recommended. ' The Tag property lets you quickly find the control ' and helps MSO keep track of it when more than ' one application window is visible. The property is required ' by some Office applications and should be provided. .Tag ="Testing" ' The OnAction property is optional but recommended. ' It should be set to the ProgID of the add-in, so that if ' the add-in is not loaded when a user clicks the button, ' MSO loads the add-in automatically and then raises ' the Click event for the add-in to handle. .OnAction ="!<MyCOMAddin.Connect>" .Visible =True EndWith EndIf cmbMenu =Nothing ctlPopup =Nothing oStandardBar =Nothing oCommandBars =Nothing End Sub PublicSub OnDisconnection()Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection OnErrorResumeNext If RemoveMode <> Extensibility.ext_DisconnectMode.ext_dm_HostShutdown Then _ Call OnBeginShutdown(custom) applicationObject =Nothing End Sub PublicSub OnConnection()Sub OnConnection(ByVal application AsObject, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst AsObject, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection applicationObject = application addInInstance = addInInst ' If you aren't in startup, manually call OnStartupComplete. If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup) Then _ Call OnStartupComplete(custom) End Sub PrivateSub CBtnCG_Click()Sub CBtnCG_Click(ByVal Ctrl As CommandBarButton, ByRef CancelDefault AsBoolean) Handles CBtnCG.Click MsgBox("Config Button of menu") End Sub PrivateSub CBtnbar_Click()Sub CBtnbar_Click(ByVal Ctrl As CommandBarButton, ByRef CancelDefault AsBoolean) Handles CBtnbar.Click MsgBox("Our CommandBar button was pressed!") End Sub End Class