Figure 3   Default OnConnection


 Private Sub IDTExtensibility_OnConnection(ByVal VBInst As Object, _
                                    ByVal ConnectMode As vbext_ConnectMode, _
                                    ByVal AddInInst As VBIDE.AddIn, _
                                    custom() As Variant)

    On Error GoTo error_handler

    'save the vb instance
    Set VBInstance = VBInst

    'this is a good place to set a breakpoint and
    'test various addin objects, properties and methods
    Debug.Print VBInst.FullName

    If ConnectMode = vbext_cm_External Then
        'Used by the wizard toolbar to start this wizard
        Me.Show
    Else
        Set mcbMenuCommandBar = AddToAddInCommandBar("My AddIn")
        'sink the event
        Set Me.MenuHandler = VBInst.Events.CommandBarEvents(mcbMenuCommandBar)
    End If

    If ConnectMode = vbext_cm_AfterStartup Then
        If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
            'set this to display the form on connect
            Me.Show
        End If
    End If

    Exit Sub

 error_handler:

    MsgBox Err.Description

 End Sub

Figure 4   Manipulating the Add-Ins Menu


 Function AddToAddInCommandBar(sCaption As String) As Office.CommandBarControl
   Dim cbMenuCommandBar As Office.CommandBarControl  'command bar object
   Dim cbMenu As Object

   On Error GoTo AddToAddInCommandBarErr

   'see if we can find the Add-Ins menu
   Set cbMenu = VBInstance.CommandBars("Add-Ins")
   If cbMenu Is Nothing Then
      'not available so we fail
      Exit Function
   End If

   'add it to the command bar
   Set cbMenuCommandBar = cbMenu.Controls.Add(1)
   'set the caption
   cbMenuCommandBar.Caption = sCaption

   Set AddToAddInCommandBar = cbMenuCommandBar

   Exit Function

 AddToAddInCommandBarErr:

 End Function