I know I've seen this code on other posts here, but couldn't find the answer I needed.
I am also very new to VBA.
I'm trying to make a custom shortcut menu for my reports, found this code on MSDN, and just copied and pasted it since I don't understand VBA enough to read it, understand it and make it unique to my database. I figured I would play around with it later to understand it better, but I haven't gotten that far.
When I try to run it I get a message "Compile Error: User-defined type not defined" and highlights the very first line.
I would really appreciate any insight on how I can use this code (or an easier way to make shortcut menus).
Code:
Sub CreateReportShortcutMenu()
Dim cmbRightClick As Office.CommandBar
Dim cmbControl As Office.CommandBarControl
' Create the shortcut menu.
Set cmbRightClick = CommandBars.Add("cmdReportRightClick", msoBarPopup, False, True)
With cmbRightClick
' Add the Print command.
Set cmbControl = .Controls.Add(msoControlButton, 2521, , , True)
' Change the caption displayed for the control.
cmbControl.Caption = "Quick Print"
' Add the Print command.
Set cmbControl = .Controls.Add(msoControlButton, 15948, , , True)
' Change the caption displayed for the control.
cmbControl.Caption = "Select Pages"
' Add the Page Setup... command.
Set cmbControl = .Controls.Add(msoControlButton, 247, , , True)
' Change the caption displayed for the control.
cmbControl.Caption = "Page Setup"
' Add the Mail Recipient (as Attachment)... command.
Set cmbControl = .Controls.Add(msoControlButton, 2188, , , True)
' Start a new group.
cmbControl.BeginGroup = True
' Change the caption displayed for the control.
cmbControl.Caption = "Email Report as an Attachment"
' Add the PDF or XPS command.
Set cmbControl = .Controls.Add(msoControlButton, 12499, , , True)
' Change the caption displayed for the control.
cmbControl.Caption = "Save as PDF/XPS"
' Add the Close command.
Set cmbControl = .Controls.Add(msoControlButton, 923, , , True)
' Start a new group.
cmbControl.BeginGroup = True
' Change the caption displayed for the control.
cmbControl.Caption = "Close Report"
End With
Set cmbControl = Nothing
Set cmbRightClick = Nothing
End Sub