We help IT Professionals succeed at work.

Syntax for menu option to execute macro or code

mlcktmguy
mlcktmguy asked
on
I need to add a menu option to an existing shortcut menu used in one of our applications.  I didn't not create the menu and barely understand how it was created.  The routine uses predefined Office number to tell the command what to execute when the option is selected.  This is the routine that creates the menu

'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Public Sub Create2013_ReportRightClickMenu()

On Error Resume Next
   
  '  CommandBars("2013_ReportRightClick").Delete
    CommandBars("ReportRightClick").Delete
   
    Dim cmbRightClick As Office.CommandBar
    Dim cmbControl As Office.CommandBarControl

    Set cmbRightClick = CommandBars.Add("2013_ReportRightClick", _
                                        msoBarPopup, False, False)
    With cmbRightClick
       
        ' Add the Print command.
        Set cmbControl = .Controls.Add(msoControlButton, 2521)
        ' Change the caption displayed for the control.
        cmbControl.Caption = "Quick Print"
       
        ' Add the Print command.
        Set cmbControl = .Controls.Add(msoControlButton, 15948)
        ' Change the caption displayed for the control.
        cmbControl.Caption = "Print ..."
       
'        ' Add the Page Setup... command.
'        Set cmbControl = .Controls.Add(msoControlButton, 247)
'        ' Change the caption displayed for the control.
'        cmbControl.Caption = "Page Setup ..."
       
        ' Add the Mail Recipient (as Attachment)... command.
        Set cmbControl = .Controls.Add(msoControlButton, 2188)
        ' Start a new group.
        cmbControl.BeginGroup = True
        ' Change the caption displayed for the control.
        cmbControl.Caption = "Email Report as an Attachment"
       
        ' Add the Export To Excel.
        Set cmbControl = .Controls.Add(msoControlButton, 11723)
        ' Change the caption displayed for the control.
        cmbControl.Caption = "Export To Excel"
       
        ' Add the PDF or XPS command.
        Set cmbControl = .Controls.Add(msoControlButton, 11725)
        ' Change the caption displayed for the control.
        cmbControl.Caption = "Expport To Word"
       
       
        ' Add the PDF or XPS command.
        Set cmbControl = .Controls.Add(msoControlButton, 12499)
        ' Change the caption displayed for the control.
        cmbControl.Caption = "Save as PDF/XPS"
     
       
    End With
   
    Set cmbControl = Nothing
    Set cmbRightClick = Nothing
End Sub
'
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I need to add an option that will either runcode or execute a macro.  I can set it up either way.  How to I change the command:

       cmbControl = .Controls.Add(msoControlButton, 12499)
 
to executue a macro 'CC2013_Macros.OpenPayForm'  or
execute a function called "openPayForm"
Comment
Watch Question

Owner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Commented:
Read my articles on Commandbars.  For what you want, you should probably start with #2, but reading #1 will help you understand the CommandBar object.

Author

Commented:
Just what I needed, thanks.