Excel精英培训网

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

关于:VBA建立自己的菜单

[复制链接]
发表于 2015-9-22 12:11 | 显示全部楼层 |阅读模式
Sub mb()
'
    MsgBox ("a")

'
End Sub
------------
Sub MyOwnMenu()
    Dim myCommandBar As CommandBar
    Dim myCommandBar_Menu1 As CommandBarControl
    Dim myCommandBar_MenuItem1 As CommandBarControl

    '这一步是新建“工具栏”
    Set myCommandBar = Application.CommandBars.Add("Serena", msoBarTop, False, False)
    '这一步是新建“弹出菜单”
    Set myCommandBar_Menu1 = myCommandBar.Controls.Add(msoControlPopup, , , , True)
    '这三行是为“弹出菜单”起个名
    With myCommandBar_Menu1
        .Caption = "菜单1"
    End With
    '这一步是新建“菜单项”
    Set myCommandBar_MenuItem1 = myCommandBar_Menu1.Controls.Add(msoControlButton, 1, , , True)
    '这三行是为“菜单项”起名,并指定宏
    With myCommandBar_MenuItem1
        .Caption = "动作1"
        .OnAction = "mb"
    End With
    ----------

问题1:点击“动作1“,弹出错误!
问题2:自己建的工具栏如何用VBA使它出现在EXCEL界面?

谢谢高人指点!!!


excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-4 16:27 , Processed in 0.506003 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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