PC Review


Reply
Thread Tools Rate Thread

Conditional enabling of menu items

 
 
Phil Hibbs
Guest
Posts: n/a
 
      30th Oct 2009
I've made an add-on that creates a menu item, but I only want it to be
enabled if there is a spreadsheet open. No, it's worse than that, I
only want it enabled if there is a cell selected. Basically I want to
mimic the behaviour of the Format->Cells menu option. How do I detect
this status and dynamically enable and disable my menu item as these
things change?

Phil Hibbs.
 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      30th Oct 2009
probably at the application event level

create a CLASS module & within this dim a variable like this:

Option Explicit
Private WithEvents xl As Excel.Application
Private Sub Class_Initialize()
Set xl = Excel.Application
End Sub
Private Sub Class_Terminate()
Set xl = Nothing
End Sub

now from the objects dropdown, select xl and the methods dropdown shows all
the available events
maybe you could use sheetactivate/deasctivate to show/hide your menu

I have this code in an XLA that loads whenever excel opens.
In a standard module I have this:

Option Explicit
Global Const BARNAME As String = "Useful"
Public xl As clsExcelApp
Sub Auto_Open()
Set xl = New clsExcelApp
End Sub

In the above code, clExcelApp is the name of my class module
the code add my 'uaseful' toolbar --- you already have code, so just call
that with the class methods as I mentioned earlier.

hope this is helpful



"Phil Hibbs" wrote:

> I've made an add-on that creates a menu item, but I only want it to be
> enabled if there is a spreadsheet open. No, it's worse than that, I
> only want it enabled if there is a cell selected. Basically I want to
> mimic the behaviour of the Format->Cells menu option. How do I detect
> this status and dynamically enable and disable my menu item as these
> things change?
>
> Phil Hibbs.
> .
>

 
Reply With Quote
 
Phil Hibbs
Guest
Posts: n/a
 
      30th Oct 2009
OK I think I've got that working - but the xl_SheetDeactivate and
xl_SheetActivate get called when changing between tabs, but not when
closing or opening a workbook, or when focus moves off a cell and onto
a control (e.g. a button or an edit box). I need to work out which
events, if the necessary events are exposed.

Phil Hibbs.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
enabling menu items and shortcut keys. MarcG Microsoft Dot NET Framework Forms 4 20th Dec 2007 02:27 AM
Enabling sub menu items via vba =?Utf-8?B?RGFuIE5lZWx5?= Microsoft Excel Programming 10 14th Jul 2005 05:35 PM
Enabling sub menu items via vba =?Utf-8?B?RGFuIE5lZWx5?= Microsoft Excel Worksheet Functions 0 11th Jul 2005 04:48 PM
Help with Enabling / Disabling Menu Items..! Applewine Microsoft Excel Programming 1 13th Jun 2005 10:37 PM
Enabling menu items mika. Microsoft Excel Misc 0 14th Sep 2003 05:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:33 AM.