用VBA代码处理菜单和工具栏之一
时 间:2004-06-21 00:00:00
作 者:郑家龙 ID:90 城市:上海
摘 要:用VBA代码处理菜单和工具栏之一
正 文:
获取菜单和工具栏的信息
在所有的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
你可以在access的Visual Basic编辑器中的立即窗口中运行这个函数得到access所有的菜单或工具栏的命令按钮,例如,可以在立即窗口中键入以下命令:
CBPrintCBarInfo(“Web”)
回车后你能在立即窗口中显示出Web工具栏所包含的所有命令集合,如下图:
如果命令按钮的类型显示为“Popup”时, 例如“收藏夹”这个命令它本身就是一个弹出式工具栏,你同样可以用本函数来得到它个每一个命令按钮的清单,如:
CBPrintCBarInfo(“favorites”)
你可以用名称或集合索引来访问工具栏集合的每个工具栏,注意与其它集合不同的是所有集合索引都是从1开始的。
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 按回车键后光标移动到下一条记录...(02.12)
- 【Access Dsum示例】...(02.07)
- Access对子窗体的数据进行...(02.05)
- 【Access高效办公】上月累...(01.09)
- 【Access高效办公】上月累...(01.06)
- Inputbox输入密码打开查...(12.23)
- 【Access Dsum示例】...(12.16)
- Inputbox输入密码打开窗...(12.13)
- 【Access DCount示...(12.02)

学习心得
最新文章
- 用Access查询语句如何得到前3...(02.17)
- Access快速开发平台--导入导...(02.14)
- 按回车键后光标移动到下一条记录的V...(02.12)
- Access快速开发平台--要实现...(02.10)
- Access快速开发平台--让Pe...(02.08)
- 【Access Dsum示例】用D...(02.07)
- Access对子窗体的数据进行平均...(02.05)
- Access快速开发平台附件上传,...(01.18)
- 【IIF函数示例】用iif函数判断...(01.18)
- Access快速开发平台--如何获...(01.17)