Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2736|回复: 3

[已解决]CommandBarControl 对象的问题

[复制链接]
发表于 2010-3-23 11:04 | 显示全部楼层 |阅读模式


Sub test1()
    Dim i As Integer

    On Error Resume Next
    CommandBars("九阴真经").Delete
    On Error GoTo 0


    '增加一个菜单栏,名叫"九阴真经",在顶部,临时
    CommandBars.Add Name:="九阴真经", Position:=msoBarTop, Temporary:=True


    '增加后默认看不到,即没打钩。Visible = True,才看得到。
    CommandBars("九阴真经").Visible = True


    '弹出框
    CommandBars("九阴真经").Controls.Add Type:=msoControlPopup

    With CommandBars("九阴真经").Controls(1)
        .Caption = "降龙十八掌"
        For i = 1 To 18
            .Controls.Add
            .Controls(i).Caption = i
            .OnAction = "haha"
        Next i
    End With
End Sub


 

 

 

我有几个地方不清楚:

  1. 希望点击"降龙十八掌"中任意一项的时候,执行haha()。结果刚点"降龙十八掌",还没展开,就执行了,请问应怎么改?
  2. 当输入CommandBars("九阴真经").Controls(1),打点后,提示列表里看不到Controls,而实际却存在。为此,我找了半天怎么新加。这算是错误吗?
  3. 可以如下图,为菜单中项目添加图标么?


N6m6LESd.rar (7.96 KB, 下载次数: 2)

CommandBarControl 对象的问题

CommandBarControl 对象的问题

srOlHj0Q.rar

7.96 KB, 下载次数: 4

CommandBarControl 对象的问题

发表于 2010-3-23 13:22 | 显示全部楼层    本楼为最佳答案   

1、错了一句:

With CommandBars("九阴真经").Controls(1)
        .Caption = "降龙十八掌"
        For i = 1 To 18
            .Controls.Add
            .Controls(i).Caption = i
            .Controls(i).OnAction = "haha"
        Next i
    End With
End Sub

2、没有点也很正常Sheets("sheet1")后面也没有点。

3、

Sub test1()
    Dim i As Integer
    On Error Resume Next
    Application.CommandBars(1).Controls("九阴真经").Delete
    On Error GoTo 0
    '增加一个菜单栏,名叫"九阴真经",在顶部,临时
    With CommandBars(1).Controls.Add(Type:=msoControlPopup, Temporary:=True)
        .Caption = "九阴真经"
        .Visible = True
        For i = 1 To 18
            .Controls.Add
            .Controls(i).Caption = i
            .Controls(i).OnAction = "haha"
        Next i
    End With
End Sub

Sub test2()
    Application.CommandBars(1).Controls("九阴真经").Delete
End Sub

回复

使用道具 举报

发表于 2010-3-23 13:25 | 显示全部楼层

CommandBars.Add              是新建一个命令栏

CommandBars(1).Controls.Add  是在菜单栏添加按钮

回复

使用道具 举报

 楼主| 发表于 2010-3-23 14:56 | 显示全部楼层

谢谢阿木!

学习了。

第2个问题,它是有提示的,只是我要找的(conrtols)正好没有,这让我很晕?

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-16 17:58 , Processed in 0.250249 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表