我尝试为我的报告创建一个ShortcutMenu,以便我可以在运行时模式下过滤rpeort。
我将以下代码添加到模块中:
Sub CreateSimpleShortcutMenu()
Dim newMenu As CommandBarControl
Dim cmb As CommandBar
On Error Resume Next 'If menu with same name exists delete
CommandBars("ShowDataShortcutMenu").Delete
CommandBars("ShowDataShortcutMenu").Delete
Set cmb = CommandBars.Add("ShowDataShortcutMenu", msoBarPopup, False, False)
With cmb
.Controls.Add(msoControlButton, 21, , , True).BeginGroup = True 'Cut
.Controls.Add msoControlButton, 19, , , True 'Copy
.Controls.Add msoControlButton, 22, , , True 'Paste
Set newMenu = .Controls.Add(msoControlButton, 4016, , , True)
newMenu.BeginGroup = True
newMenu.Caption = "&Sort A to Z"
newMenu.OnAction = "=SortAZ()"
Set newMenu = .Controls.Add(msoControlButton, 4017, , , True)
newMenu.Caption = "S&ort Z to A"
newMenu.OnAction = "=SortZA()"
.Controls.Add msoControlButton, 605, , , True 'Remove Filter/Sort
Set newMenu = .Controls.Add(Type:=msoControlPopup)
newMenu.Caption = "Te&xt Filters"
newMenu.Controls.Add msoControlButton, 10077, , , True 'Filter equals xx
newMenu.Controls.Add msoControlButton, 10078, , , True 'Filter not equal to xx
newMenu.Controls.Add msoControlButton, 10079, , , True 'Filter beings with xx
newMenu.Controls.Add msoControlButton, 12696, , , True 'Filter does not beings with xx
newMenu.Controls.Add msoControlButton, 10080, , , True 'Filter contains xx
newMenu.Controls.Add msoControlButton, 10081, , , True 'Filter does not contains xx
newMenu.Controls.Add msoControlButton, 10082, , , True 'Filter ends with xx
newMenu.Controls.Add msoControlButton, 10083, , , True 'Filter ends with xx
newMenu.Controls.Add msoControlButton, 12697, , , True 'Filter does not ends with xx
End With
Set cmb = Nothing
Set newMenu = Nothing
End Sub
Function SortAZ()
CommandBars.ExecuteMso ("SortUp")
End Function
Function SortZA()
CommandBars.ExecuteMso ("SortDown")
End Function
在Reports.OnLoad中,我致电
CreateSimpleShortCutMenu
我还需要将快捷菜单设置为属性,但是当我去报告属性时它没有出现 - >其他 - >快捷菜单
有人能帮助我吗?
编辑:我也收到此错误信息: 用户定义的类型未定义"错误消息
答案 0 :(得分:0)
代码按预期工作。 缺少的是对象库的引用。 我添加了参考,它工作。
甚至可以在运行时使用。