We help IT Professionals succeed at work.
Get Started

Syntax for menu option to execute macro or code

mlcktmguy
mlcktmguy asked
on
243 Views
Last Modified: 2015-02-27
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
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE