Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Managing menus via VBA

Does anyone know if there is a way to add items to a submenu in VBA. I
have a VBA program that manipulates data for creating data sets to be
analyzed in SAS and a neural network package. The data processing
commands for adding lags to the data set, splitting the data set into
training and verification data sets and importing the results
predicted by SAS and the neural network are currently in a custom
menu that I added. As these commands are essentially data commands I
am shifting them to the Data menu that already exists in Excel.

Adding the commands to the bottom of the Data menu is a no-brainer; I
even figured out how to add a divider bar. The thing is that two of
my custom commands are import functions and it makes more sense to
add these two commands to the Data Import External Data submenu.
VBA help provides no information for doing this. I also tried the
common sense approach:

..Menus("Data")[color=blue:b69d32f640].MenuItems[/color:b69d32f640]("Import
External Data")[color=blue:b69d32f640].Add[/color:b69d32f640] _
[color=blue:b69d32f640]Caption[/color:b69d32f640]:="Import SAS®
Predictions...", _
[color=blue:b69d32f640]OnAction[/color:b69d32f640]:="ReadSASDataSet"

The VBA compiler sees no problem with this code, but when it is
executed the addition of a specific menu item caused the program to
halt with an unsupported property or method error.

Any assistance that can be provided would be greatly appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Managing menus via VBA

You're using the Menus method that has been hidden since Excel 97. While it
can be make to work I suppose I'd suggest using the preferred Commandbars
method.

Sub AddSASItem()
Dim NewCtrl As CommandBarButton
Set NewCtrl = CommandBars("Worksheet Menu Bar") _
.Controls("Data").Controls("Import External Data") _
.Controls.Add
NewCtrl.Caption = "Import SAS® Predictions..."
NewCtrl.OnAction = "ReadSASDataSet"
End Sub


--
Jim
"mddawson - ExcelForums.com"
wrote in message ...
| Does anyone know if there is a way to add items to a submenu in VBA. I
| have a VBA program that manipulates data for creating data sets to be
| analyzed in SAS and a neural network package. The data processing
| commands for adding lags to the data set, splitting the data set into
| training and verification data sets and importing the results
| predicted by SAS and the neural network are currently in a custom
| menu that I added. As these commands are essentially data commands I
| am shifting them to the Data menu that already exists in Excel.
|
| Adding the commands to the bottom of the Data menu is a no-brainer; I
| even figured out how to add a divider bar. The thing is that two of
| my custom commands are import functions and it makes more sense to
| add these two commands to the Data Import External Data submenu.
| VBA help provides no information for doing this. I also tried the
| common sense approach:
|
| Menus("Data")[color=blue:b69d32f640].MenuItems[/color:b69d32f640]("Import
| External Data")[color=blue:b69d32f640].Add[/color:b69d32f640] _
| [color=blue:b69d32f640]Caption[/color:b69d32f640]:="Import SAS®
| Predictions...", _
| [color=blue:b69d32f640]OnAction[/color:b69d32f640]:="ReadSASDataSet"
|
| The VBA compiler sees no problem with this code, but when it is
| executed the addition of a specific menu item caused the program to
| halt with an unsupported property or method error.
|
| Any assistance that can be provided would be greatly appreciated.
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Managing menus via VBA

Thanks Jim. The Menubars technique is what I learned from my faculty
advisor two years ago so I will have to let him know that we should
be using CommandBars instead. Excel does provide help text on the
MenuBars command (we have Office 2002), but there is nothing about
accesing the submenu of a menubar menu. I will try your suggestion
out and let you know how it goes.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Managing menus via VBA

I tried the CommandBars technique and it worked well. It is more code
intensive than the MenuBars method, but it does allow access to
submenus. Another difference is that the CommandBars property does
not recognize the caption “-” as a group separator. If I indicate a
hyphen as the caption using the MenuBars property I get the
horizontal rule (group separator) in the menu bar, but with
CommandBars it just appears as a hyphen. How do I get the group
separator using the CommandBars property?

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
Sub-menus of main menus for Excel 2007 Eleanor Peppard New Users to Excel 1 March 16th 10 04:12 PM
difference between word 2003 menus and word 2007 menus-Explain pl kali Excel Discussion (Misc queries) 1 August 29th 07 07:56 AM
New Menus - attaching but menus are reset Greegan Excel Worksheet Functions 0 November 5th 05 03:19 PM
Managing User Changes Peter[_44_] Excel Programming 1 August 9th 04 12:12 PM
Overriding Actions of Excel DropDown Menus and Poup Menus Von Shean Excel Programming 2 February 3rd 04 06:43 AM


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