VBA创建一个“录入窗体”工具栏

看了几遍也没看懂这个帖子,http://club.excelhome.net/thread-290608-1-1.html
现在总算理解了 <梦想成真>的示例了.
例如创建一个“录入窗体”工具栏:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Private Sub Workbook_Activate()
    On Error Resume Next
    Application.CommandBars("我的工具栏").Delete
    Dim 子菜单 As CommandBarControl
         
    For m = 1 To 2
    Select Case m
    
    Case 1
    
    Set 主菜单 = Application.CommandBars.Add
    With 主菜单
    
    .Visible = True
    .Name = "我的工具栏"
    .Position = msoBarTop------------改成msoBarLeft 0 命令栏固定在应用程序窗口的左侧。
    
    End With
    
    Case 2
    
    Set 主菜单 = Application.CommandBars("Cell").Controls.Add(Type:=msoControlPopup, before:=1)
    主菜单.Caption = "工具栏"
    End Select
    
    For i = 1 To 1
    
    Set 子菜单 = 主菜单.Controls.Add(Type:=msoControlButton)
    
    With 子菜单
    
    .Caption = Array("录入窗体")(i - 1)
    .Style = msoButtonIconAndCaptionBelow
    .OnAction = Array("录入窗体")(i - 1)
    .FaceId = 284
    .BeginGroup = True
    End With
    Next
    Next
End Sub
 
Private Sub Workbook_Deactivate()
    On Error Resume Next
    Application.CommandBars("我的工具栏").Delete
    Application.CommandBars("Cell").Controls("工具栏").Delete
End Sub
 
 
---------------------
 
这句代码放在模块内:
 
Public Sub 录入窗体()
    UserForm1.Show
End Sub

相关内容链接
CommandBars对象模型树信息(已总结)http://club.excelhome.net/viewth ... ighlight=commandbar
如何在自定义工具栏内添加文本输入框 http://club.excelhome.net/viewth ... =%B9%A4%BE%DF%C0%B8
如果用VBA写一段自动加入菜单功能 http://club.excelhome.net/viewth ... p;page=1#pid2385602
xlsExplorerDemo.xls(代码公开) http://club.excelhome.net/viewthread.php?tid=31707&px=0
灵活设计自定义工具栏 http://club.excelhome.net/viewthread.php?tid=44814
使自定义工具栏上的按钮显示(不显示)是否处于选中状态 http://club.excelhome.net/thread-141699-1-546.html
怎样在VBA中将自定义工具栏的图标换成指定的图标? http://club.excelhome.net/viewth ... p;extra=&page=1
如何固定自定义工具栏的位置 http://club.excelhome.net/thread-326819-1-1.html
如何实现自定义工具栏中的分隔线  http://club.excelhome.net/thread-40298-1-1.html
这个文件为什么会自动生成一个工具栏? http://club.excelhome.net/thread-222293-1-1.html
自定义菜单工具栏加载ImageList储藏的图标 http://club.excelhome.net/thread-255940-1-1.html
怎样给自定义菜单加批注  http://club.excelhome.net/thread-253012-1-1.html
遍历不能在thiswork中运行,只能在Sheet1 Sheet2 Sheet3中运行下面程序.

1
2
3
4
5
6
7
8
9
10
Sub EnaBar()
    Dim myBar As CommandBar
    Debug.Print CommandBars.Count
    For Each myBar In CommandBars
      Debug.Print myBar.Name
        If myBar.Type = msoBarTypePopup Then
            myBar.Enabled = True
        End If
    Next
End Sub
posted @   多见多闻  阅读(914)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示