VBA 给Excel添加自定义菜单栏

2019-07-22 14:59:32 浏览数 (1)

代码语言:javascript复制
    Sub SetMenu()
        Dim myBar As CommandBar
        Dim myButton As CommandBarButton
        Set myBar = CommandBars.Add(Name:="vb小源码", _
            Position:=msoBarTop, _
            MenuBar:=True)
        Set myButton = myBar.Controls.Add(msoControlButton)
        myButton.Style = msoButtonCaption
        myButton.Caption = "退出[&E]"
        myButton.OnAction = "ExitSYS"
        Set myButton = myBar.Controls.Add(msoControlButton)
        myButton.Style = msoButtonCaption
        myButton.Caption = "返回[&R]"
        myButton.OnAction = "ReturnMAIN"
        myButton.Visible = True
        myBar.Protection = msoBarNoMove   msoBarNoCustomize
        myBar.Visible = True
    End Sub
vba

0 人点赞