2

我正在更新一些旧的 VBA 代码以使用 Access 2010。我们遇到的一个问题是右键单击时没有出现快捷菜单,因此我们创建了一个快捷菜单并将其绑定到 Application 对象,如下所示...

Application.ShortcutMenuBar = "GeneralClipboardMenu"

一般来说,如果您右键单击“详细信息”窗格中的列“我们将其用作 excel 网格”,则不会出现菜单。这方面对我们的应用程序的使用至关重要,因此我们不能忽略它。

代码中的任何地方都没有禁用快捷菜单。此外,我意识到快捷菜单正在被 2010 Office 套装中的功能区所取代,但右键单击是我们理想情况下希望保留的基本功能。

任何帮助将不胜感激。这是创建快捷菜单的代码,以防万一。

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
4

3 回答 3

1

实际上,我发现了一个令人满意的解决方法。我们需要能够右键单击列的唯一原因是为了排序。当您右键单击一个单元格时,使用我最初拥有的代码,排序选项显示为灰色。然而,排序命令似乎有几个 id,它们都有不同的功能。

http://support.microsoft.com/kb/159466

上面的链接有一个可用 id 的快捷菜单列表。

我相当肯定没有办法在 2010 详细信息窗格中为整个列添加右键单击功能。我没有在任何地方禁用菜单,我通过搜索任何能够执行此操作的命令以及三重检查我的属性来执行此操作。

于 2012-06-28T17:10:14.743 回答
1

我相信应用程序范围的快捷菜单栏是 DAO 数据库属性。您可以在 GUI 中的 Access Options > Current Database > Ribbon and Toolbar Options 下更改它。

您也可以使用以下代码更改它:

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
于 2012-06-28T15:17:12.983 回答
0

一种可能性是快捷菜单在表单属性中设置为“否”。您可以通过在设计视图中查看表单,然后查看表单属性并检查“快捷菜单”设置来访问这些内容。它应该设置为“是”。

于 2012-06-27T18:02:42.997 回答