mlcktmguy
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_ReportRightClic kMenu()
On Error Resume Next
' CommandBars("2013_ReportRi ghtClick") .Delete
CommandBars("ReportRightCl ick").Dele te
Dim cmbRightClick As Office.CommandBar
Dim cmbControl As Office.CommandBarControl
Set cmbRightClick = CommandBars.Add("2013_Repo rtRightCli ck", _
msoBarPopup, False, False)
With cmbRightClick
' Add the Print command.
Set cmbControl = .Controls.Add(msoControlBu tton, 2521)
' Change the caption displayed for the control.
cmbControl.Caption = "Quick Print"
' Add the Print command.
Set cmbControl = .Controls.Add(msoControlBu tton, 15948)
' Change the caption displayed for the control.
cmbControl.Caption = "Print ..."
' ' Add the Page Setup... command.
' Set cmbControl = .Controls.Add(msoControlBu tton, 247)
' ' Change the caption displayed for the control.
' cmbControl.Caption = "Page Setup ..."
' Add the Mail Recipient (as Attachment)... command.
Set cmbControl = .Controls.Add(msoControlBu tton, 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(msoControlBu tton, 11723)
' Change the caption displayed for the control.
cmbControl.Caption = "Export To Excel"
' Add the PDF or XPS command.
Set cmbControl = .Controls.Add(msoControlBu tton, 11725)
' Change the caption displayed for the control.
cmbControl.Caption = "Expport To Word"
' Add the PDF or XPS command.
Set cmbControl = .Controls.Add(msoControlBu tton, 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(msoControlBu tton, 12499)
to executue a macro 'CC2013_Macros.OpenPayForm ' or
execute a function called "openPayForm"
'/////////////////////////
Public Sub Create2013_ReportRightClic
On Error Resume Next
' CommandBars("2013_ReportRi
CommandBars("ReportRightCl
Dim cmbRightClick As Office.CommandBar
Dim cmbControl As Office.CommandBarControl
Set cmbRightClick = CommandBars.Add("2013_Repo
msoBarPopup, False, False)
With cmbRightClick
' Add the Print command.
Set cmbControl = .Controls.Add(msoControlBu
' Change the caption displayed for the control.
cmbControl.Caption = "Quick Print"
' Add the Print command.
Set cmbControl = .Controls.Add(msoControlBu
' Change the caption displayed for the control.
cmbControl.Caption = "Print ..."
' ' Add the Page Setup... command.
' Set cmbControl = .Controls.Add(msoControlBu
' ' Change the caption displayed for the control.
' cmbControl.Caption = "Page Setup ..."
' Add the Mail Recipient (as Attachment)... command.
Set cmbControl = .Controls.Add(msoControlBu
' 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(msoControlBu
' Change the caption displayed for the control.
cmbControl.Caption = "Export To Excel"
' Add the PDF or XPS command.
Set cmbControl = .Controls.Add(msoControlBu
' Change the caption displayed for the control.
cmbControl.Caption = "Expport To Word"
' Add the PDF or XPS command.
Set cmbControl = .Controls.Add(msoControlBu
' 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(msoControlBu
to executue a macro 'CC2013_Macros.OpenPayForm
execute a function called "openPayForm"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER