' the Event object used to get a notification when
' the user clicks on newMenuItem
Private WithEvents MenuHandler As CommandBarEvents
Attribute MenuHandler.VB_VarHelpID = -1
' this is the form corresponding to this instance of the class
Dim frmAddin As New frmAddin
Private Sub IDTExtensibility_OnConnection(ByVal VBInst As Object, ByVal ConnectMode As vbext_ConnectMode, ByVal AddInInst As VBIDE.AddIn, custom() As Variant)
On Error GoTo OnConnection_Error
'save the VB instance
Set VBInstance = VBInst
If ConnectMode <> vbext_cm_Startup Then
' if no AfterStartup method will be called, this is the right
' place to add a menu item to the Add-Ins menu
CreateMenuItem
End If
Exit Sub
OnConnection_Error:
MsgBox "Unable to correctly connect the add-in", vbCritical
End Sub
Private Sub IDTExtensibility_OnStartupComplete(custom() As Variant)
' if the add-in is being loaded at VB startup, this is
' the right place to add a menu item to the Add-Ins menu
CreateMenuItem
End Sub
Private Sub IDTExtensibility_OnDisconnection(ByVal RemoveMode As vbext_DisconnectMode, custom() As Variant)
On Error Resume Next
'delete the menu item
newMenuItem.Delete
' clear the menu handler object
Set MenuHandler = Nothing
' unload the form, if necessary
Unload frmAddin
Set frmAddin = Nothing
End Sub
Private Sub IDTExtensibility_OnAddInsUpdate(custom() As Variant)
'
End Sub
Sub CreateMenuItem()
Dim addInMenu As Object
On Error Resume Next
' search the Add-Ins menu, exit if not found
' (very unlikely)
Set addInMenu = VBInstance.CommandBars("Add-Ins")
If (Err <> 0) Or (addInMenu Is Nothing) Then Exit Sub
' add a new item to the Add-In menu, after existing ones
Set newMenuItem = addInMenu.Controls.Add(1)
' set it caption to a suitable string, with a hotkey
newMenuItem.Caption = "&Property Builder..."
' create a menu handler object that will receive
' a click event when the user select the menu command
Set MenuHandler = VBInstance.Events.CommandBarEvents(newMenuItem)
End Sub
Private Sub MenuHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)