Link to home
Start Free TrialLog in
Avatar of mlcktmguy
mlcktmguyFlag for United States of America

asked on

Syntax for menu option to execute macro or code

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"
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mlcktmguy

ASKER

Just what I needed, thanks.