Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Add Menu Items

Instead of placing buttons on my spreadsheet, I want to add custom menu
options that the user can select to execute my vba code. How is this
possible?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Add Menu Items

Mike,

A good place for this would be the workbook open event:-

For Each menubar In MenuBars
With menubar.Menus("help")
Call .MenuItems.Add("My Text", "Mymacroname")
End With
Next

This simply adds the text "My Text" to the help menu and if the user clicks
it a macro called "Mymacroname" is executed.

Mike

"Mike H." wrote:

Instead of placing buttons on my spreadsheet, I want to add custom menu
options that the user can select to execute my vba code. How is this
possible?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Add Menu Items

That is exactly what I want to do. Is is also possible to create your own
menu option on the "top-level" menu instead of adding to one of the existing
menus?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Add Menu Items

Mike,

Yes you can do that. The code below adds a menu item and 2 sub menu items
that run 2 very un-exciting macros. Also included is the nacro to ger rid of
the custom menu item:-

Sub AddMenus()
Dim Menu1 As CommandBarControl
Dim MainMenuBar As CommandBar
Dim CustomMenu As CommandBarControl
On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("&New Menu").Delete
On Error GoTo 0
Set MainMenuBar = Application.CommandBars("Worksheet Menu Bar")
HelpMenu = MainMenuBar.Controls("Help").Index
Set CustomMenu = MainMenuBar.Controls.Add(Type:=msoControlPopup,
Befo=HelpMenu)
CustomMenu.Caption = "&New Menu"
With CustomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "This Choice"
.OnAction = "MyMacro1"
End With

With CustomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "That Choice"
.OnAction = "MyMacro2"
End With
End Sub

Sub myMacro1()
MsgBox ("You ran myMacro1")
End Sub

Sub myMacro2()
MsgBox ("You ran myMacro2")
End Sub

Sub DeleteMenu()
On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("&New Menu").Delete
On Error GoTo 0
End Sub

"Mike H." wrote:

That is exactly what I want to do. Is is also possible to create your own
menu option on the "top-level" menu instead of adding to one of the existing
menus?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default Add Menu Items

From: Mike H.
[msg 1]
From: Mike H
[msg 2]
From: Mike H.
[msg 3]
From: Mike H
[msg 4]

OK, there's a period in the the first and third.
And, there's two guys talking to each other. (Aren't there?)
My question: How is it that you both have the
same "?

Sorry to be off-topic. D-C

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----


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
VBA:programmatically invoking menu items from Excel Worksheet menu morse100 Excel Programming 15 October 29th 10 07:29 PM
Custom Menu and Menu Items Steve[_91_] Excel Programming 4 August 16th 07 02:15 AM
New menu items Daniel Bonallack Excel Programming 2 November 2nd 05 07:59 PM
Menu items added with menu item editor in older versions Michael Hoffmann Excel Discussion (Misc queries) 2 January 7th 05 01:40 PM
Sub Menu Items pauluk[_72_] Excel Programming 1 July 27th 04 12:23 PM


All times are GMT +1. The time now is 07:33 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"