Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a menu item added to the Tools menu called MyMenu. I'm trying to tie
it to a VBA subroutine I've written called MySub. I have this code for the menu. Application.CommandBars("Worksheet menu bar").Controls("Tools").Controls.Add(Type:=msoCont rolButton).Caption = "MyMenu" Application.CommandBars("Worksheet menu bar").Controls("Tools").Controls("MyMenu").OnActio n = MySub Then I created a new module with this code. Private Sub MySub () MsgBox ("My subroutine") End Sub When I select the MyMenu command from the Tools menu, nothing happens so I'm obviously not making the linkage correctly. Any help would be greatly appreciated. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Did you try removing the Parens from the Msgbox line??? or Try making MySub
public. B "Kent McPherson" wrote in message ... I have a menu item added to the Tools menu called MyMenu. I'm trying to tie it to a VBA subroutine I've written called MySub. I have this code for the menu. Application.CommandBars("Worksheet menu bar").Controls("Tools").Controls.Add(Type:=msoCont rolButton).Caption = "MyMenu" Application.CommandBars("Worksheet menu bar").Controls("Tools").Controls("MyMenu").OnActio n = MySub Then I created a new module with this code. Private Sub MySub () MsgBox ("My subroutine") End Sub When I select the MyMenu command from the Tools menu, nothing happens so I'm obviously not making the linkage correctly. Any help would be greatly appreciated. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
One way:
With CommandBars.FindControl(Id:=30007).Controls.Add( _ Type:=msoControlButton) .Caption = "MyMenu" .OnAction = "MySub" End With Using the Id is generally better than using the names/captions, since names and captions are language specific, and in any case can be changed. In article , "Kent McPherson" wrote: I have a menu item added to the Tools menu called MyMenu. I'm trying to tie it to a VBA subroutine I've written called MySub. I have this code for the menu. Application.CommandBars("Worksheet menu bar").Controls("Tools").Controls.Add(Type:=msoCont rolButton).Caption = "MyMenu" Application.CommandBars("Worksheet menu bar").Controls("Tools").Controls("MyMenu").OnActio n = MySub Then I created a new module with this code. Private Sub MySub () MsgBox ("My subroutine") End Sub When I select the MyMenu command from the Tools menu, nothing happens so I'm obviously not making the linkage correctly. Any help would be greatly appreciated. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This was very helpful. Thanks.
"JE McGimpsey" wrote in message ... One way: With CommandBars.FindControl(Id:=30007).Controls.Add( _ Type:=msoControlButton) .Caption = "MyMenu" .OnAction = "MySub" End With Using the Id is generally better than using the names/captions, since names and captions are language specific, and in any case can be changed. In article , "Kent McPherson" wrote: I have a menu item added to the Tools menu called MyMenu. I'm trying to tie it to a VBA subroutine I've written called MySub. I have this code for the menu. Application.CommandBars("Worksheet menu bar").Controls("Tools").Controls.Add(Type:=msoCont rolButton).Caption = "MyMenu" Application.CommandBars("Worksheet menu bar").Controls("Tools").Controls("MyMenu").OnActio n = MySub Then I created a new module with this code. Private Sub MySub () MsgBox ("My subroutine") End Sub When I select the MyMenu command from the Tools menu, nothing happens so I'm obviously not making the linkage correctly. Any help would be greatly appreciated. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
And you have another response at your other thread.
Kent McPherson wrote: I have a menu item added to the Tools menu called MyMenu. I'm trying to tie it to a VBA subroutine I've written called MySub. I have this code for the menu. Application.CommandBars("Worksheet menu bar").Controls("Tools").Controls.Add(Type:=msoCont rolButton).Caption = "MyMenu" Application.CommandBars("Worksheet menu bar").Controls("Tools").Controls("MyMenu").OnActio n = MySub Then I created a new module with this code. Private Sub MySub () MsgBox ("My subroutine") End Sub When I select the MyMenu command from the Tools menu, nothing happens so I'm obviously not making the linkage correctly. Any help would be greatly appreciated. -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Triggering an action when an item is selected from a dropdown menu | Excel Worksheet Functions | |||
Command button to move completed action item | Excel Discussion (Misc queries) | |||
Action Item Worksheet Creation | Excel Worksheet Functions | |||
Trigger Action when Standard Menu Item Selected? | Excel Discussion (Misc queries) | |||
Menu Item Action Changes with "User" accessing file | Excel Programming |