Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 1st, 2004, 12:42 AM
Authorized User
 
Join Date: Feb 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom Menu

In excel 200 VBA Programmer's Reference Chapter 12 page 207.
Creating New menus.
It works nicely, but my problem is, When I activate certain sheets in the workbook, then I would like to set some of the menu items to
Enabled = False. Can anyone help with this.

 
Old June 1st, 2004, 05:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The answer to your problem is to associate the code with the SheetActivate / SheetDeactivate events.
Go to the codepage associated with ThisWorkbook for whichever project you are working in.
At the top left of the actual CodePage, there is a dropdown that probably says '(General)'. Click this and select 'Workbook'. You will now see that top right dropdown's contents have changed (and Excel has probably created a 'Workbook_Open' event stub for you).
Click on the dropdown and select 'SheetActivate', you will see Excel place an Event stub on the CodePage for you. All you need to do now is place the code to enable your CommandBar here.
If you only want the command bar to appear for certain sheets, you can use the Default parameter 'sh' to determine the name of the activated worksheet (i.e. sh.Name) and write conditional logic for your particular scenario.
Don't forget to do the same thing for the 'SheetDeactivate' event, too.

Chris

There are two secrets to success in this world:
1. Never tell everything you know
 
Old June 2nd, 2004, 12:29 AM
Authorized User
 
Join Date: Feb 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey again
Maybe i did not make my self clear. So here is my example.

This just like the book and works fine.
Application.CommandBars("File").Controls("Save").E nabled = False

This is a part of my Custom Menu.
It contains several items but I only want to disable "Opdater Statestik"

Private Sub Worksheet_Activate()

  Application.CommandBars("Slagelse Dart Klub").Controls ("Opdater Statestik").Enabled = False
end sub

But that dosn't work. Can anyone help with this. I have now spend a lot of time on this and I really stoked.

Thanks in advance
Karsten

 
Old June 2nd, 2004, 03:17 AM
Authorized User
 
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The "Name" property of the CommandBar object, or the "Caption" property of the CommandBarButton object you are referencing must be incorrect

Try referencing the control by its numeric index to see if that improves your result, eg

Application.CommandBars("Slagelse Dart Klub").Controls(x).Enabled = False

..where x = the position of the control in the custom toolbar

If it works, you could try printing the Caption property to the debug window to see what the application thinks the named index should be.
 
Old June 3rd, 2004, 01:20 AM
Authorized User
 
Join Date: Feb 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your suggestion.
Unfortunatly it didn't work.
In debug mode I get "Invalid procedure call or argument"
I have tried to run the macro Third level controls and here the menu is present. So now I am really lost. I hope someone can help.
The main problem is that if some of the menu item are processed from certain sheets it will result in very strange outputs.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Menu Paula222 ASP.NET 1.x and 2.0 Application Design 0 November 8th, 2006 09:21 AM
Custom Menu Paula222 .NET Framework 2.0 0 November 8th, 2006 09:08 AM
Creating Custom Menu Component in JSF.....Pls help Finny J2EE 0 September 10th, 2004 06:24 AM
Custom Menu... Almost SerranoG Access 5 January 30th, 2004 09:50 AM
Custom Menu Manipulation SerranoG Access 0 June 19th, 2003 03:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.