如何用VBA在WORD中创建命令栏(即菜单项)菜单项,能传参给调用宏,与excel的onAction不一样。 5
我自己创建了一个菜单栏,但想点击菜单,会调用输入参数的函数,目前试了好多方法不成功。请高手指点下~'ctrl1.OnAction="ShowForm1"Subcreate...
我自己创建了一个菜单栏,但想点击菜单,会调用输入参数的函数,目前试了好多方法不成功。 请高手指点下~
'ctrl1.OnAction = "ShowForm1"
Sub createMenu()
Dim myMenuBar As CommandBar
Dim newMenu As CommandBarPopup
Dim ctrl1 As CommandBarButton '初始化菜单
Set myMenuBar = Application.ActiveDocument.CommandBars.ActiveMenuBar
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlPopup, _ Temporary:=True)
newMenu.Caption = "值班记事"
Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, ID:=1)
ctrl1.Caption = "提取上班"
ctrl1.Style = msoButtonIconAndCaption
ctrl1.FaceId = 2109 ctrl1.OnAction = "ShowForm ""1"""
ctrl1.Visible = True
End Sub
Sub ShowForm1(i_msg As String)
MsgBox i_msg
End Sub
无参数的话,是可以调用无参数的宏。有参数就不行~ 展开
'ctrl1.OnAction = "ShowForm1"
Sub createMenu()
Dim myMenuBar As CommandBar
Dim newMenu As CommandBarPopup
Dim ctrl1 As CommandBarButton '初始化菜单
Set myMenuBar = Application.ActiveDocument.CommandBars.ActiveMenuBar
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlPopup, _ Temporary:=True)
newMenu.Caption = "值班记事"
Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, ID:=1)
ctrl1.Caption = "提取上班"
ctrl1.Style = msoButtonIconAndCaption
ctrl1.FaceId = 2109 ctrl1.OnAction = "ShowForm ""1"""
ctrl1.Visible = True
End Sub
Sub ShowForm1(i_msg As String)
MsgBox i_msg
End Sub
无参数的话,是可以调用无参数的宏。有参数就不行~ 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询