|
以下是引用gzk在2002-3-17 9:47:51的发言:
在自定义菜单的示例代码中任何菜单项下,加上如下语句:
Set Ctrl1 = newMenu.Controls.Add(Type:=msoControlPopup, Id:=1)
Ctrl1.Caption = "自建二级菜单"
再启动就可出现二级菜单容器符号和空框。这一步,是成功的。
这时,用第三种方法,向该框中添加命令,并录制下来。可惜的是,得到的代码不能执行。
这个问题是:如何接着向二级菜单容器中添加命令。这是本人解决不了的问题,希望各位高手来攻下这个难题。
我很同意这样的观点:各位高手把自己的一般性的常用的基础性的实用的得意之作制成示例发布,对初学者是个捷径,在这样的基础上进行研究讨论,肯定能再提高本论坛的水平。
果泽奎
这个问题可以解决,参阅以下代码
Option Explicit
Sub CreateMenu()
Dim Menu As CommandBarControl, SubMenu As CommandBarControl
Set Menu = Application.CommandBars(1).Controls.Add(msoControlPopup, , , , True)
With Menu
.Caption = "我的菜单(&M)"
End With
With Menu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "菜单1"
.OnAction = "wswx"
End With
With Menu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "菜单2"
.OnAction = "wswx"
End With
Set SubMenu = Menu.Controls.Add(msoControlPopup, 1, , , True)
With SubMenu
.Caption = "菜单3"
.BeginGroup = True
End With
With SubMenu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "子菜单1"
.OnAction = "wswx"
.Style = msoButtonIconAndCaption
.FaceId = 71
End With
With SubMenu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "子菜单2"
.OnAction = "wswx"
.Style = msoButtonIconAndCaption
.FaceId = 72
End With
Set SubMenu = SubMenu.Controls.Add(msoControlPopup, 1, , , True)
With SubMenu
.Caption = "子菜单3"
.BeginGroup = True
End With
With SubMenu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "二级菜单1"
.OnAction = "wswx"
.Style = msoButtonIconAndCaption
.FaceId = 71
End With
With SubMenu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "二级菜单2"
.OnAction = "wswx"
.Style = msoButtonIconAndCaption
.FaceId = 72
End With
With Menu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "删除菜单"
.OnAction = "DeleteMenu"
.Style = msoButtonIconAndCaption
.FaceId = 463
.BeginGroup = True
End With
End Sub
Sub wswx()
MsgBox "这只是个范例!", vbInformation, "制作:WSWX"
End Sub
Sub DeleteMenu()
Application.CommandBars(1).Controls("我的菜单(&M)").Delete
End Sub |
|