帐号: 密码:
// 设为首页 // 收藏本站 // 请您留言 // 网址导航
远方教程-满足你的求知欲!
站内搜索:
HTML ASP PHP CSS DIV Dreamweaver Photoshop Word Excel PPT SEO技巧
您当前位置:网站首页 >> Office教程 >> VBA入门教程 >> 阅读文章

用VBA添加菜单和子菜单的示例代码

来源:远方教程 作者:远方教程 发布时间:2017-05-30 查看次数:1731 访问[新版]

在excel里,用VBA添加菜单和子菜单的示例代码:
Sub 添加菜单()
On Error Resume Next
Application.CommandBars("人事管理主菜单").Delete
Dim 主菜单 As CommandBar
Dim 子菜单 As CommandBarControl
Set 主菜单 = Application.CommandBars.Add(temporary:=True)
Dim BER As CommandBarControl
  With 主菜单
    .Visible = True
    .Name = "人事管理主菜单"
    .Position = msoBarTop
    '******************开始添加文件子菜单*********************
    Set 子菜单 = 主菜单.Controls.Add(Type:=msoControlPopup)
        子菜单.Caption = "文件(&F)"
      With 子菜单
       Set BER = .Controls.Add(Type:=msoControlButton)
           With BER
            .Caption = "保存"
            .BeginGroup = True
            .OnAction = "保存"
            .FaceId = 3
           End With
       Set BER = .Controls.Add(Type:=msoControlButton)
           With BER
             .Caption = "打印预览    "
             .BeginGroup = True
             .OnAction = "打印预览"
             .FaceId = 109
           End With
        Set BER = .Controls.Add(Type:=msoControlButton)
           With BER
            .Caption = "打印"
            .FaceId = 4
            .OnAction = "打印"
           End With
        Set BER = .Controls.Add(Type:=msoControlButton)
          With BER
           .Caption = "退出"
           .BeginGroup = True
           .OnAction = "退出"
           .FaceId = 1640
          End With
        End With
       '。。。。。。。。。。添加文件子菜单结束。。。。。。。。。。。
       '******************开始添加员工信息子菜单*********************
      Set 子菜单 = 主菜单.Controls.Add(Type:=msoControlPopup)
         子菜单.Caption = "员工信息(&Y)"
      With 子菜单
       Set BER = .Controls.Add(Type:=msoControlButton)
           With BER
            .Caption = "员工信息基本操作"
            .BeginGroup = True
            .OnAction = "显示员工信息窗口"
            .FaceId = 65
           End With
       Set BER = .Controls.Add(Type:=msoControlButton)
           With BER
             .Caption = "员工信息筛选"
             .BeginGroup = True
             .OnAction = "显示员工信息查询工作表"
             .FaceId = 140
           End With
       End With
        '。。。。。。。。。。添加员工信息子菜单结束。。。。。。。。。。。
       '******************开始设置子菜单*********************
          Set 子菜单 = 主菜单.Controls.Add(Type:=msoControlPopup)
      子菜单.Caption = "设置(&S)"
      With 子菜单
       Set BER = .Controls.Add(Type:=msoControlButton)
           With BER
            .Caption = "添加基本信息"
            .BeginGroup = True
          .OnAction = "显示基础信息工作表"
            .FaceId = 451
           End With
       Set BER = .Controls.Add(Type:=msoControlButton)
           With BER
             .Caption = "备份文件"
             .BeginGroup = True
             .OnAction = "文件备份"
             .FaceId = 173
           End With
        Set BER = .Controls.Add(Type:=msoControlButton)
           With BER
            .Caption = "添加操作员"
            .BeginGroup = True
            .FaceId = 469
            .OnAction = "添加操作员"
           End With
        End With
      '。。。。。。。。。。添加设置子菜单结束。。。。。。。。。。。
    End With
    Set 主菜单 = Nothing
    Set 子菜单 = Nothing
    Set BER = Nothing
End Sub

打印 打印 | 关闭 关闭 评论
相关文章
图片新闻
站内搜索  
搜索
猜您喜欢  
最新更新  
阅读排行  
关于我们 | 联系方式 | 大事记 | 免责声明 | | 给我留言
部分广告源自金山联盟2345联盟 QQ咨询 站长之家QQ群:232617873
Copyright 2020 远方教程 © All Rights Reserved.

回顶部