Code Block
Private Sub AddCommandToMenu(ByVal strMenuName As String, ByRef command As Office.CommandBarButton, ByVal strCommandName As String, ByVal pos As Integer, Optional ByVal strPictureName As String = "", Optional ByVal strMaskName As String = "", Optional ByVal iPictureId As Integer = 0)
Dim menu As Office.CommandBarPopup
menu = app.CommandBars.ActiveMenuBar.FindControl(Office.MsoControlType.msoControlPopup, , strMenuName)
command = menu.CommandBar.FindControl(Office.MsoControlType.msoControlButton, , strCommandName)
If (command IsNot Nothing) Then
command.Delete()
End If
command = menu.Controls.Add(Office.MsoControlType.msoControlButton, , "", pos, True)
command.Caption = strCommandName
command.Tag = strCommandName
If (Not (String.IsNullOrEmpty(strPictureName))) Then
command.Picture = GetImage(strPictureName)
If (Not (String.IsNullOrEmpty(strMaskName))) Then
command.Mask = GetImage(strMaskName)
End If
ElseIf (iPictureId <> 0) Then
command.BuiltInFace = True
command.FaceId = iPictureId
End If
End Sub