用VBA代码处理菜单和工具栏之四
时 间:2004-06-21 00:00:00
作 者:郑家龙 ID:90 城市:上海
摘 要:用VBA代码处理菜单和工具栏之四
正 文:
复制菜单和工具栏
必需用VBA代码才能复制现有的工具栏。你可以用Add方法创建一个和你要拷贝相同类型的工具栏,然后再用CommandBarControl对的Copy方法将源工具栏上的每一个命令按钮复制到新工具栏上,下面的函数将是以这种方法实现复制工具栏:
strOrigCBName参数是指被复制的源工具栏,strNewCBName参数指新工具栏的名称,可选参数blnShowBar决定了新工具栏是否显示出来。
Function CBCopyCommandBar(strOrigCBName As String, _
strNewCBName As String, _
Optional blnShowBar As Boolean = False) As Boolean
' This procedure copies the command bar named in the strOrigCBName
' argument to a new command bar specified in the strNewCBName argument.
Dim cbrOriginal As CommandBar
Dim cbrCopy As CommandBar
Dim ctlCBarControl As CommandBarControl
Dim lngBarType As Long
On Error GoTo CBCopy_Err
Set cbrOriginal = CommandBars(strOrigCBName)
lngBarType = cbrOriginal.Type
Select Case lngBarType
Case msoBarTypeMenuBar
Set cbrCopy = CommandBars.Add(Name:=strNewCBName, Position:=msoBarMenuBar)
Case msoBarTypePopup
Set cbrCopy = CommandBars.Add(Name:=strNewCBName, Position:=msoBarPopup)
Case Else
Set cbrCopy = CommandBars.Add(Name:=strNewCBName)
End Select
' Copy controls to new command bar.
For Each ctlCBarControl In cbrOriginal.Controls
ctlCBarControl.Copy cbrCopy
Next ctlCBarControl
' Show new command bar.
If blnShowBar = True Then
If cbrCopy.Type = msoBarTypePopup Then
cbrCopy.ShowPopup
Else
cbrCopy.Visible = True
End If
End If
CBCopyCommandBar = True
CBCopy_End:
Exit Function
CBCopy_Err:
CBCopyCommandBar = False
Resume CBCopy_End
End Function
注意:
1.这个函数的strNewCBName参数不能和现有工具栏中同名;
2.如果你复制一个弹出式菜单栏,并且设blnShowBar参数为TRUE,当运行这个函数时,这个弹出式菜单栏将显示在当前鼠标的位置,更多的关于显示弹出式菜单栏的信息和描述请参阅Microsoft Office Visual Basic Reference Help 中的“显示弹出式菜单栏”索引。
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 【Access选项卡示例】Ac...(09.09)
- 【Access源码示例】按输入...(09.02)
- 【Access日期区间段查询】...(08.29)
- 【Access日期区间段查询】...(08.27)
- Access怎样才能实现日期时...(08.21)
- 【Access定时打开查询】A...(08.19)
- Access生成固定数量的记录...(08.13)
- Access怎样才能实现日期时...(08.12)
- Access利用导航窗体控件对...(08.03)
学习心得
最新文章
- Access表中的字段名、字段标题...(09.19)
- Access快速开发平台--更改“...(09.18)
- 【中秋及国庆优惠】Access培训...(09.15)
- Access如何将日期型的数值转换...(09.14)
- 英文输入法输入数据中存在单引号引起...(09.11)
- 【Access选项卡示例】Acce...(09.09)
- 让Access光标停留在指定的控件...(09.07)
- 关于Access查询条件里使用通配...(09.06)
- Access报表偷懒制作法--Ac...(09.05)
- Access快速开发平台--窗体数...(09.04)