设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用VBA代码处理菜单和工具栏之一

1970-1-1 08:00| 发布者: zhengjialon『文章』| 查看: 3426| 评论: 0

                              -------------------郑家龙编绎于MS OFFICE开发文档

获取菜单和工具栏的信息

 

在所有的OFFICE组件应用程序中都包含有内置的工具栏,并且可以进行进一步的自定义显示相关命令,它们一共有三种类型:菜单栏,工具栏和弹出式菜单栏(本主题以工具栏代表三种类型来描述)。

你可以用下面的一段程序在立即窗口中显示它们的所有的工具栏以及工具栏上所包含的命令控件:

Function CBPrintCBarInfo(strCBarName As String) As Variant

    ' This procedure prints (to the Debug window) information

    ' about the command bar specified in the strCBarName argument

    ' and information about each control on that command bar.

   

    Dim cbrBar                      As CommandBar

    Dim ctlCBarControl              As CommandBarControl

    Const ERR_INVALID_CMDBARNAME    As Long = 5

   

    On Error GoTo CBPrintCBarInfo_Err

   

    Set cbrBar = Application.CommandBars(strCBarName)

   

    Debug.Print "CommandBar: " & cbrBar.Name & vbTab & "(" _

        & CBGetCBType(cbrBar) & ")" & vbTab & "(" _

        & IIf(cbrBar.BuiltIn, "Built-in", "Custom") & ")"

    For Each ctlCBarControl In cbrBar.Controls

        Debug.Print vbTab & ctlCBarControl.Caption & vbTab & "(" _

            & CBGetCBCtlType(ctlCBarControl) & ")"

    Next ctlCBarControl

 

CBPrintCBarInfo_End:

    Exit Function

CBPrintCBarInfo_Err:

    Select Case Err.Number

        Case ERR_INVALID_CMDBARNAME

            CBPrintCBarInfo = "'" & strCBarName & _

                "' is not a valid command bar name!"

        Case Else

            CBPrintCBarInfo = "Error: " & Err.Number _

                & " - " & Err.Description

    End Select

    Resume CBPrintCBarInfo_End

End Function

 

你可以在ACCESSVisual Basic编辑器中的立即窗口中运行这个函数得到ACCESS所有的菜单或工具栏的命令按钮,例如,可以在立即窗口中键入以下命令:

? CBPrintCBarInfo(“Web”)

 

回车后你能在立即窗口中显示出Web工具栏所包含的所有命令集合,如下图:

 

 

如果命令按钮的类型显示为“Popup”时, 例如“收藏夹”这个命令它本身就是一个弹出式工具栏,你同样可以用本函数来得到它个每一个命令按钮的清单,如:

? CBPrintCBarInfo(“favorites”)

 

你可以用名称或集合索引来访问工具栏集合的每个工具栏,注意与其它集合不同的是所有集合索引都是从1开始的。

最新评论

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-9 03:24 , Processed in 0.076643 second(s), 16 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部