首页 EXCEL工具栏细解

EXCEL工具栏细解

举报
开通vip

EXCEL工具栏细解CommandBar介绍-工具栏 接着介绍CommandBar的三个类型之一,工具栏。 工具栏 创建工具栏很简单,直接使用CommandBars集合的Add方法,除了需要指定Name属性之外,可以接受其它所有的默认属性值。可以通过Position属性指定工具栏显示的位置。 Position属性的值由msoBarPosition常数指定。 msoBarLeft: 0,工具栏显示在工作表左边 msoBarTop: 1,工具栏显示在工作表上边 msoBarRight: 2,工具栏显示在工作表右边 m...

EXCEL工具栏细解
CommandBar介绍-工具栏 接着介绍CommandBar的三个类型之一,工具栏。 工具栏 创建工具栏很简单,直接使用CommandBars集合的Add方法,除了需要指定Name属性之外,可以接受其它所有的默认属性值。可以通过Position属性指定工具栏显示的位置。 Position属性的值由msoBarPosition常数指定。 msoBarLeft: 0,工具栏显示在工作 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 左边 msoBarTop: 1,工具栏显示在工作表上边 msoBarRight: 2,工具栏显示在工作表右边 msoBarBottom: 3,工具栏显示在工作表下边 msoBarFloating: 4,工具栏浮动显示 msoBarMenuBar: 5,这个常数表示创建菜单栏,不用于创建工具栏 msoBarPopup: 6,这个常数表示创建弹出菜单 例如下面的代码创建名称为“Custom Toolbar”的位于工作表区域上边的工具栏。 Set newTool = CommandBars.Add(Name:="Custom Toolbar", Position:=msoBarTop) 创建好CommandBar对象后,可以使用它的Controls集合的Add方法添加控件,也就是工具命令栏。 可以通过Add方法参数中的Type属性指定命令栏的类型。Type属性由msoControlType常数指定。 msoControlButton:1,普通按钮类型 msoControlEdit:2,编辑框类型 msoControlDropdown:3,复合框类型,不能输入新项目 msoControlComboBox :4,和DropDown一样的复合框类型,允许输入新项目 msoControlPopup:10,弹出菜单 如果在Add方法中指定ID属性的值,可以创建内置命令栏,例如设置id:=3则创建“保存”命令栏,不需要知道OnAction属性,点击该命令栏将执行默认保存命令。 还可以设置命令栏的Style属性。Style属性由msoButtonStyle或msoComboStyle常数指定。 msoButtonStyle常数: msoButtonAutomatic:0,默认值,对于菜单栏,等于msoButtonIconAndCaption,对于工具栏,等于msoButtonIcon msoButtonCaption:2,只显示标题,忽略图标 msoButtonIcon:1,在工具栏上只显示图标,在菜单栏上只显示标题 msoButtonIconAndCaption:3,显示图标,并在图标右边显示标题 msoButtonIconAndCaptionBelow:7,对于菜单栏,等同于msoButtonIconAndCaption,对于工具栏,在图标下方显示标题 msoButtonWrapCaption:14 ,同msoButtonCaption类似,只是如果标题太长时分行显示 msoComboStyle常数: msoComboLabel:1,左边有标题 msoComboNormal:0,没有标题 如果命令栏的Type属性设置为msoControlComboBox,该命令栏可以使用ComboBox控件的各种方法和属性,例如AddItem方法、Clear方法等。如果创建时设置了Caption属性为“请选择:”,则可以使用Controls(”请选择:”)来表示该复合框命令栏。例如下面的代码: With CommandBars("Custom Toolbar").Controls("请选择:") 下面是一个创建工具栏的完整例子。 Sub CreateToolBar() Dim newTool As CommandBar Dim i As Integer '如果发现有相同工具栏,删除该工具栏 On Error Resume Next CommandBars("Custom Toolbar").Delete On Error GoTo 0 '添加名称为“Custom Toolbar”的工具栏,并在工作表上方显示 Set newTool = CommandBars.Add(Name:="Custom Toolbar", Position:=msoBarTop) With newTool .Visible = True With .Controls.Add(Type:=msoControlButton) .Caption = "复制" .Style = msoButtonIconAndCaption .TooltipText = "复制文件" .FaceId = 18 .OnAction = "HandleTool" End With With .Controls.Add(Type:=msoControlButton, ID:=3) .Caption = "保存" .BeginGroup = True .Style = msoButtonIcon End With With .Controls.Add(Type:=msoControlEdit) .Caption = "输入:" .BeginGroup = True .Style = msoButtonIcon .TooltipText = "在此输入数据" .OnAction = "HandleText" End With With .Controls.Add(Type:=msoControlComboBox) .Caption = "请选择:" .BeginGroup = True .Style = msoComboLabel .TooltipText = "请选择所需项目" .AddItem "Apple" .AddItem "Banana" .AddItem "Orange" .ListIndex = 1 .OnAction = "HandleCombo" End With End With End Sub Sub ExecuateCombo() With CommandBars("Custom Toolbar").Controls("请选择:") MsgBox .ListCount If .List(1) = "Apple" Then .Execute End If End With End Sub Sub HandleCombo() Dim sCall As String sCall = CommandBars.ActionControl.Text MsgBox "你选择了: " & sCall, vbInformation End Sub Sub HandleText() Dim sCall As String sCall = CommandBars.ActionControl.Text MsgBox "你输入了: " & sCall, vbInformation End Sub Sub HandleTool() Dim sCall As String sCall = CommandBars.ActionControl.Caption MsgBox "你点击了: " & sCall, vbInformation End Sub Sub RemoveToolBar() On Error Resume Next CommandBars("Custom Toolbar").Delete End Sub 本示例创建命令栏“Custom”,向命令栏中添加三个按钮,然后用 ActionControl 属性和 Tag 属性确定最后一次单击的是哪一个命令栏按钮。 Set myBar = CommandBars _ .Add(Name:="Custom", Position:=msoBarTop, _ Temporary:=True) Set buttonOne = myBar.Controls.Add(Type:=msoControlButton) With buttonOne .FaceId = 133 .Tag = "RightArrow" .OnAction = "whichButton" End With Set buttonTwo = myBar.Controls.Add(Type:=msoControlButton) With buttonTwo .FaceId = 134 .Tag = "UpArrow" .OnAction = "whichButton" End With Set buttonThree = myBar.Controls.Add(Type:=msoControlButton) With buttonThree .FaceId = 135 .Tag = "DownArrow" .OnAction = "whichButton" End With myBar.Visible = True whichButton 子程序响应 OnAction 方法并确定最后单击的是哪一个命令栏按钮。 Sub whichButton() Select Case CommandBars.ActionControl.Tag Case "RightArrow" MsgBox ("Right Arrow button clicked.") Case "UpArrow" MsgBox ("Up Arrow button clicked.") Case "DownArrow" MsgBox ("Down Arrow button clicked.") End Select End Sub 设置Excel自定义工具栏的通用代码 Private Sub Workbook_Open() '自定义工具栏 Dim Mybar As CommandBar Set Mybar = Application.CommandBars.Add(Name:="汇总表工具", Position:=msoBarTop, Temporary:=True) '增加菜单栏 Dim MyPopup As CommandBarPopup Set MyPopup = Mybar.Controls.Add(Type:=msoControlPopup) MyPopup.Caption = "汇总工具" '增加菜单项 Dim MyButton As CommandBarButton Set MyButton = MyPopup.Controls.Add(Type:=msoControlButton, ID:=2949) With MyButton .Caption = "贴到新表中(&D)" .Style = msoButtonCaption .OnAction = "Sheet1.贴到新表中" .FaceId = 280 End With '增加菜单项 Set MyButton = MyPopup.Controls.Add(Type:=msoControlButton) With MyButton .Caption = "清空表格(&D)" .OnAction = "Sheet1.清空表格" .FaceId = 285 .Style = msoControlButton End With Set MyButton = MyPopup.Controls.Add(Type:=msoControlButton) MyButton.Caption = "菜单项二" Set MyButton = MyPopup.Controls.Add(Type:=msoControlButton) MyButton.Caption = "菜单项三" Mybar.Visible = True Set mCommand = Mybar.Controls.Add(Type:=msoControlButton, ID:=2949) With mCommand .Caption = "汇总工作簿(&T)" .OnAction = "Sheet1.汇总" .Style = msoButtonCaption .BeginGroup = True '添加分组线 End With Set mCommand = Mybar.Controls.Add(Type:=msoControlButton, ID:=2949) With mCommand .Caption = "选择工作簿目录(&D)" .OnAction = "Sheet1.选择目录" .Style = msoButtonIconAndCaption '设置工具栏图标 .FaceId = 303 End With With Application.CommandBars("汇总表工具") .Visible = True .Position = 4 .Top = 380 .Left = 710 End With End sub Private Sub Workbook_BeforeClose(Cancel As Boolean) Application.CommandBars("汇总表工具").Delete On Error Resume Next End Sub Style 属性应用于 CommandBarButton 对象的情形。 返回或设置命令栏按钮控件的显示方式。MsoButtonStyle 类型,可读写。 MsoButtonStyle 可为以下 MsoButtonStyle 常量之一: msoButtonAutomatic msoButtonCaption msoButtonIcon msoButtonIconAndCaption msoButtonIconAndCaptionBelow msoButtonIconAndWrapCaption msoButtonIconAndWrapCaptionBelow msoButtonWrapCaption
本文档为【EXCEL工具栏细解】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_126878
暂无简介~
格式:doc
大小:39KB
软件:Word
页数:6
分类:互联网
上传时间:2013-03-22
浏览量:37