VBA 详细信息快捷菜单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11230966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA Detail Shortcut Menu
提问by user1149651
I am updating some old VBA code to work with Access 2010. One problem we encountered is that no Shortcut Menu appears when you right click so we create a shortcut menu and bound it to the Application object like so...
我正在更新一些旧的 VBA 代码以使用 Access 2010。我们遇到的一个问题是右键单击时没有出现快捷菜单,因此我们创建了一个快捷菜单并将其绑定到应用程序对象,如下所示...
Application.ShortcutMenuBar = "GeneralClipboardMenu"
In general this works however if you right click on a column in a Detail pane, "Which we are using as an excel grid", no menu appears. This aspect is critical to the use of our application so we can not ignore it.
通常,如果您右键单击“详细信息”窗格中的列,“我们将其用作 Excel 网格”,则不会出现任何菜单。这方面对于我们的应用程序的使用至关重要,因此我们不能忽视它。
Nowhere in the code are Shortcut Menus being disable. Also I realize shortcut menus are being replaced by the ribbon in the 2010 Office suit however right click is a basic feature that we would ideally like to keep.
代码中没有任何地方禁用快捷菜单。我也意识到快捷菜单正在被 2010 Office 套装中的功能区所取代,但右键单击是我们希望保留的基本功能。
Any help would be greatly appreciated. Here is the code for creating the shortcut menu in-case it is relevant.
任何帮助将不胜感激。这是用于创建快捷菜单的代码,以防万一。
Sub CreateSimpleShortcutMenu()
On Error Resume Next 'If menu with same name exists delete
CommandBars("GeneralClipboardMenu").Delete
Dim cmb As CommandBar
Set cmb = CommandBars.Add("GeneralClipboardMenu", msoBarPopup, False, False)
With cmb
.Controls.Add msoControlButton, 21, , , True ' Cut
.Controls.Add msoControlButton, 19, , , True ' Copy
.Controls.Add msoControlButton, 22, , , True ' Paste
.Controls.Add msoControlButton, 4016, , , True 'Sort Ascending
.Controls.Add msoControlButton, 4017, , , True 'Sort Decending
End With
Set cmb = Nothing
End Sub
回答by HK1
I believe the Application-wide Shortcut Menu bar is a DAO database property. You can change it in the GUI under Access Options > Current Database > Ribbon and Toolbar Options.
我相信应用程序范围的快捷菜单栏是 DAO 数据库属性。您可以在 GUI 中的 Access Options > Current Database > Ribbon and Toolbar Options 下更改它。
You can also change it using the following code:
您还可以使用以下代码更改它:
UpdateCustomProperty("StartupShortcutMenuBar", "NameOfMyCustomShortcutMenuBar")
Private Function CreateCustomProperty(ByVal sPropertyName As String, _
ByVal sPropertyValue As String)
On Error Resume Next
If sPropertyName <> "" And sPropertyValue <> "" Then
Dim p1 As DAO.Property
Set p1 = CurrentDb.CreateProperty(sPropertyName, DB_TEXT, sPropertyValue)
CurrentDb.Properties.Append p1
Set p1 = Nothing
End If
End Function
Public Function UpdateCustomProperty(ByVal sPropertyName As String, _
ByVal sPropertyValue As String)
On Error Resume Next
If sPropertyName <> "" And sPropertyValue <> "" Then
CurrentDb.Properties(sPropertyName) = sPropertyValue
If Err.Number = 3270 Then
Err.Clear
Call CreateCustomProperty(sPropertyName, sPropertyValue)
End If
End If
Err.Clear
End Function
回答by user1149651
Actually I discovered a workaround that is satisfactory. The only reason we needed to be able to right click a column was for sorting. Using the code I initially had when you right clicked a cell the sort options where grayed out. However it appears there are several id's for sort commands and they all have different functionality.
实际上,我发现了一个令人满意的解决方法。我们需要能够右键单击列的唯一原因是为了排序。使用我最初拥有的代码,当您右键单击一个单元格时,排序选项会变灰。然而,似乎有几个用于排序命令的 id,它们都有不同的功能。
http://support.microsoft.com/kb/159466
http://support.microsoft.com/kb/159466
The above link has a list of available id's for shortcut menus.
上面的链接列出了快捷菜单的可用 ID。
I am fairly sure there is no way to add right click functionality to entire columns in 2010 detail panes. Nowhere was I disabling menus I did a through search for any commands capable of doing that as well as triple checking my properties.
我相当确定没有办法在 2010 详细信息窗格中向整个列添加右键单击功能。我无处禁用菜单,我通过搜索任何能够执行此操作的命令以及三重检查我的属性。
回答by Doug Glancy
One possibility is that Shortcut Menu is set to "No" in the form properties. You can access these by viewing the form in design view, then viewing Form Properties, and checking the "Shortcut Menu" setting. It should be set to "Yes."
一种可能性是快捷菜单在表单属性中设置为“否”。您可以通过在设计视图中查看表单,然后查看表单属性,并检查“快捷菜单”设置来访问这些。它应该设置为“是”。