MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 4th, 2002, 08:08 AM   #1
jgoulart
Board Regular
 
Join Date: Feb 2002
Location: John G
Posts: 62
Default

How can I write vba code to hide different menu items? I want to make the "Send to" selection under "File" hidden or grayed out. I also want to gray out "Macro" under "Tools".

John
jgoulart is offline   Reply With Quote
Old Mar 4th, 2002, 10:22 PM   #2
Corni
Board Regular
 
Join Date: Mar 2002
Location: Brampton
Posts: 324
Default

The menu items which are part of Excel application cannot be controlled programatically for permanent modification. The only option available, which is relatively limited in extent is the Customize menu item, which allows a reduced level of customization to respond to personal preferences and working habits.
The possibility of disabling by code menu items exist only for This Workbook macros.

[ This Message was edited by: corni on 2002-03-05 19:05 ]

[ This Message was edited by: corni on 2002-03-06 19:44 ]
Corni is offline   Reply With Quote
Old Mar 4th, 2002, 11:16 PM   #3
viper
Board Regular
 
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
Default

This is what I did from the help here as well. Open VB editor and under General Declarations for This Workbook type the following:
Dim CB As CommandBar
Dim C As CommandBarControl
Dim ID

Then insert a module in This Workbook and type the following:

Sub Disable_RightClick_Toolbar()
ID = 30017
For Each CB In Application.CommandBars
Set C = CB.FindControl(ID:=ID, recursive:=True)
If Not C Is Nothing Then C.Enabled = False
Next
Application.CommandBars("Toolbar List").Enabled = False
Application.CommandBars("Visual Basic").Enabled = False

End Sub

Then insert a second one and type the following:

Sub Enable_RightClick_ToolBar()

ID = 30017
For Each CB In Application.CommandBars
Set C = CB.FindControl(ID:=ID, recursive:=True)
If Not C Is Nothing Then C.Enabled = True
Next
Application.CommandBars("ToolBar List").Enabled = True
Application.CommandBars("Visual Basic").Enabled = True

End Sub

Then in This Workbook Open event type:
Disable_RightClick_Toolbar

and in This Workbook Deactivate() type:
Enable_RightClick_Toolbar.

This worked great for me but their is one flaw and I hope whoever else reads this can help me fix this. But after you do the above and then save and re-open the file, the macro will be greyed under the tools menu, but if you leave that file open and then open a second file and then close it the macro will be enabled again. I haven't figured out how to stop that from happening but as long as the user doesn't know about the second file then your macro will remain greyed. As far as the other menu item I don't know but maybe this will give you a head start in modifying the code for the other item.

HTH

__________________
I appreciate the help from everyone at Mr. Excel.

viper
viper is offline   Reply With Quote
Old Mar 4th, 2002, 11:20 PM   #4
viper
Board Regular
 
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
Default

Forgot to mention. For both of the module inserts you will need to put the following before the code as well as in the General Declarations for This Workbook:
Dim CB As CommandBar
Dim C As CommndBarControl
Dim ID
viper is offline   Reply With Quote
Old Mar 4th, 2002, 11:40 PM   #5
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

For graying out the File|Send To, use this code (you don't need to set the commandbar or the first popup, but I've done it as an example)



Dim CmdBar As CommandBar
Dim CmdBarControl As CommandBarPopup
Dim SendToControl As CommandBarPopup

Set CmdBar = Application.CommandBars("Worksheet Menu Bar")
Set CmdBarControl = CmdBar.Controls("&File")
Set SendToControl = CmdBarControl.Controls("Sen&d To")

'Remember to set this to True before exiting Excel
SendToControl.Enabled = False


For the Tools|Macro button do the same except put in "&Tools" instead of "&File"
and "&Macro" instead of "Sen&d To".

***Remember to reset these values to True before exiting Excel.

Cheers


_________________
[b] Mark O'Brien

[ This Message was edited by: Mark O'Brien on 2002-03-04 22:40 ]

[ This Message was edited by: Mark O'Brien on 2002-03-04 22:41 ]
Mark O'Brien is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 03:14 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes