【问题标题】:View Info Of Custom Menu查看自定义菜单的信息
【发布时间】:2017-05-12 02:49:49
【问题描述】:

在 Access 2003 中,创建了一个自定义菜单。如何使用 VBA 查看菜单的详细信息?

I.E.打印出每个选项的作用? (它运行的名称和查询) 如果自定义菜单有“每天运行”选项,并且它的作用是运行标题为 qry_dly 的查询

然后我希望看到这样的 VBA 输出 每日运行 --> qry_dly

【问题讨论】:

    标签: vba ms-access ms-access-2003


    【解决方案1】:

    这可能需要一些调整,具体取决于菜单的结构。但是一旦你掌握了它的工作原理,你应该能够在需要时对其进行更改。

    首先,您需要找出自定义菜单的名称。如果您已经知道,请跳过此步骤。否则获取从这里返回的名称:

     Dim x As Integer
     For x = 1 To CommandBars.Count
        If CommandBars(x).BuiltIn = False Then
          Debug.Print x, CommandBars(x).Name, CommandBars(x).BuiltIn
       End If
     Next x
    

    然后,将自定义菜单的名称传递给此过程。就像我说的,根据菜单的设置方式,这可能会或可能不会返回其中的所有内容,这就是您可能需要对其进行自定义的地方:

    Private Sub ReadMenuControls(ByVal strCmdBar As String)
    
    On Error GoTo errhandler
    
    Dim x, y As Integer
    
    Dim SubMenu As Object
    
     With CommandBars(strCmdBar)
      Debug.Print "Control Count Main: ", .Controls.Count
    
          For x = 1 To .Controls.Count
                With .Controls(x)
                Debug.Print x & " <== " & .Caption & " ==>"
                        If .Type = 1 Then 'Command Button
    
                             Debug.Print "Button", x, .Caption, .Type, .ID, .FaceId, .Style, .onaction
    
                        Else 'If .Type = 10 Then  'Menu
    
                            Set SubMenu = CommandBars(strCmdBar).Controls(x)
    
                            For y = 1 To SubMenu.Controls.Count
                                  With .Controls(y)
                                     Debug.Print "  * Button", y, .Caption, .Type, .ID, .FaceId, .Style, .onaction
                                  End With
                            Next
                       End If
                End With
          Next
    
     End With
    
    Exit Sub
    
    errhandler:
     If Err.Number <> 438 Then
      Debug.Print "ReadMenuControls", Err.Number, Err.description
     End If
     Resume Next
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-12
      • 2013-01-03
      • 1970-01-01
      相关资源
      最近更新 更多