VBA多级菜单
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 | Sub GOINMYSUB() MsgBox "成功进入我的过程!!" End Sub Sub MyMenu() Dim Popup(5) Dim Button(5) As CommandBarControl On Error Resume Next DeleteOldDMenu '单清除旧菜 ' 建立新菜單 Set Popup(0) = Application.CommandBars.Add( "MyVAB" , Position:=msoBarTop) Popup(0).Visible = True Lastrow = Range( "E65536" ).End(xlUp).Row I = 2 Do While I <= Lastrow For K = 1 To 3 If Cells(I, K) <> Empty Then Popup(K + 1) = Empty '清空有关数据 Popup(K + 2) = Empty Exit For End If Next If Cells(I, 5) = Empty Then ' 建立子菜單 Set Popup(K) = Popup(K - 1).Controls.Add(Type:=msoControlPopup, Temporary:=True) ' Popup(K).Caption = Cells(I, K).Text Else ' 建立按钮快键 Set Button(K) = Popup(K - 1).Controls.Add(Type:=msoControlButton, Temporary:=True) Button(K).Caption = Cells(I, K).Text Button(K).FaceId = Cells(I, 4) Button(K).OnAction = Cells(I, 5).Text End If I = I + 1 Loop End Sub Sub DeleteOldDMenu() On Error Resume Next Application.CommandBars( "MyVAB" ).Delete End Sub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!