Imports Microsoft.Office.Core
imports Extensibility
Imports System.Runtime.InteropServices
#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 SMSOutlookSetup project
' by right clicking the project in the Solution Explorer, then choosing install.
#End Region
<GuidAttribute("EF730A67-8CCE-4F1F-9EFA-F5880F767DD0"), ProgIdAttribute("SMSOutlook.Connect")> _
Public Class Connect
Implements Extensibility.IDTExtensibility2
Public applicationObject As Object
Public addInInstance As Object
Public WithEvents cmdbarMyAddin As CommandBarButton
Private frmMyForm As New frmMine
Public ReadOnly Property OutlookObject()
Get
applicationObject = OutlookObject
End Get
End Property
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
On Error Resume Next
' Notify the user you are shutting down, and delete the button.
frmMyForm.Dispose()
frmMyForm = Nothing
cmdbarMyAddin.Delete()
cmdbarMyAddin= Nothing
End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub
' This event fires (I think) when Outlook has finished loading. Most of the code was auto generated by the
'AddIn (On error resume next), how nice.
' Basically it will add a button called MyAddin to the Outlook main window.
Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
Dim oCommandBars As CommandBars
Dim oStandardBar As CommandBar
On Error Resume Next
' Set up a custom button on the "Standard" command bar.
oCommandBars = applicationObject.CommandBars
If oCommandBars Is Nothing Then
' Outlook has the CommandBars collection on the Explorer object.
oCommandBars = applicationObject.ActiveExplorer.CommandBars
End If
oStandardBar = oCommandBars.Item("Standard")
' In case the button was not deleted, use the exiting one.
cmdbarMyAddin = oStandardBar.Controls.Item("My Addin")
If cmdbarMyAddin Is Nothing Then
cmdbarMyAddin = oStandardBar.Controls.Add(1)
With cmdbarMyAddin
.Caption = "My Addin"
'.Style = MsoButtonStyle.msoButtonIcon
.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 = "My Addin"
' 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
End With
End If
' Display a simple message to show which application you started in.
oStandardBar = Nothing
oCommandBars = Nothing
End Sub
Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
On Error Resume Next
If RemoveMode <> Extensibility.ext_DisconnectMode.ext_dm_HostShutdown Then _
Call OnBeginShutdown(custom)
applicationObject = Nothing
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
' If you aren't in startup, manually call OnStartupComplete.
If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup) Then _
Call OnStartupComplete(custom)
End Sub
Private Sub cmdbarMyAddin_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles cmdbarMyAddin.Click
Try
Dim frmMyForm As New frmMine
frmMyForm = New frmSms
frmMyForm.Outlookref = CType(applicationObject, Outlook.Application)
frmMyForm.Show()
Catch ex As Exception
MsgBox("An error has occured with the AddIn." & vbCrLf & "Error details : " & Err.Description)
End Try
End Sub
End Class