Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default New menu item action

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default New menu item action

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default New menu item action

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default New menu item action

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default New menu item action

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triggering an action when an item is selected from a dropdown menu Xonnel1212 Excel Worksheet Functions 1 July 2nd 09 12:17 AM
Command button to move completed action item JFREE223 Excel Discussion (Misc queries) 4 February 5th 08 06:54 PM
Action Item Worksheet Creation Kevin M[_2_] Excel Worksheet Functions 0 February 26th 07 09:16 PM
Trigger Action when Standard Menu Item Selected? Filibuster Excel Discussion (Misc queries) 2 July 26th 06 12:49 AM
Menu Item Action Changes with "User" accessing file windsurferLA Excel Programming 1 June 15th 05 08:00 PM


All times are GMT +1. The time now is 02:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"