PC Review


Reply
Thread Tools Rate Thread

Add-In Menu Handling

 
 
Stephen Lloyd
Guest
Posts: n/a
 
      3rd Nov 2009
I'm using Excel 2003. I have an add-in that creates a menu in the
workbook open event and uses a class module to handle application
level events. Call that xlApp.

In the xlApp_WorkbookBeforeClose() event I call code to remove the
menu. This works fine if the user is removing the add-in in the
traditional sense, i.e. Tools>AddIns etc. There is, however, an
undesired behavior when a user is attempting to close a workbook and
mistakenly clicks the close icon for the Excel Application.

If all workbooks were saved when the user misclicked, then tough luck,
restart excel. If, however, there were unsaved changes in one or more
workbooks the user is graced with an opportunity to catch their
error. A dialog box appears with options Yes, [Yes to all], No, and
Cancel. If the user selects cancel, then none of the workbooks will
close.

The problem is that the BeforeClose() events for one or more workbooks
have already fired and the add-ins menu was removed.

So, I'm looking for a way to detect this situation and either avoid
deleting the menu or add the menu again.

In what order does Excel run the BeforeClose() events? ( I assume in
the index order of the workbooks)
Application level events are fairly limited and consist mostly of
events for child objects, however, as I write this I'm wondering if
something in the WindowActivate event might work.

Any one have a solution to this problem
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      4th Nov 2009
There's no direct way to trap an aborted close after the CloseEvent has run.
At least not in VBA although there are various approaches with the help of a
ComAddin to call back to the addin to run close code (it's close event runs
when close cannot be aborted).

A simple workaround is in the close event to include an OnTime macro to
reapply the removed menus later if the addin still exists, say 8 seconds is
generally enough. You also need to set a flag in the AddinUninstall event
to prevent that OnTime macro.

Regards,
Peter T


"Stephen Lloyd" <(E-Mail Removed)> wrote in message
news:1dc3adad-2044-4fcd-8cde-(E-Mail Removed)...
> I'm using Excel 2003. I have an add-in that creates a menu in the
> workbook open event and uses a class module to handle application
> level events. Call that xlApp.
>
> In the xlApp_WorkbookBeforeClose() event I call code to remove the
> menu. This works fine if the user is removing the add-in in the
> traditional sense, i.e. Tools>AddIns etc. There is, however, an
> undesired behavior when a user is attempting to close a workbook and
> mistakenly clicks the close icon for the Excel Application.
>
> If all workbooks were saved when the user misclicked, then tough luck,
> restart excel. If, however, there were unsaved changes in one or more
> workbooks the user is graced with an opportunity to catch their
> error. A dialog box appears with options Yes, [Yes to all], No, and
> Cancel. If the user selects cancel, then none of the workbooks will
> close.
>
> The problem is that the BeforeClose() events for one or more workbooks
> have already fired and the add-ins menu was removed.
>
> So, I'm looking for a way to detect this situation and either avoid
> deleting the menu or add the menu again.
>
> In what order does Excel run the BeforeClose() events? ( I assume in
> the index order of the workbooks)
> Application level events are fairly limited and consist mostly of
> events for child objects, however, as I write this I'm wondering if
> something in the WindowActivate event might work.
>
> Any one have a solution to this problem



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      4th Nov 2009
Another option would be to give the routine that builds the toolbar/menu a
shortcut key.

Then tell the user that if they don't see the toolbar/menu to hit the shortcut
key.



Stephen Lloyd wrote:
>
> I'm using Excel 2003. I have an add-in that creates a menu in the
> workbook open event and uses a class module to handle application
> level events. Call that xlApp.
>
> In the xlApp_WorkbookBeforeClose() event I call code to remove the
> menu. This works fine if the user is removing the add-in in the
> traditional sense, i.e. Tools>AddIns etc. There is, however, an
> undesired behavior when a user is attempting to close a workbook and
> mistakenly clicks the close icon for the Excel Application.
>
> If all workbooks were saved when the user misclicked, then tough luck,
> restart excel. If, however, there were unsaved changes in one or more
> workbooks the user is graced with an opportunity to catch their
> error. A dialog box appears with options Yes, [Yes to all], No, and
> Cancel. If the user selects cancel, then none of the workbooks will
> close.
>
> The problem is that the BeforeClose() events for one or more workbooks
> have already fired and the add-ins menu was removed.
>
> So, I'm looking for a way to detect this situation and either avoid
> deleting the menu or add the menu again.
>
> In what order does Excel run the BeforeClose() events? ( I assume in
> the index order of the workbooks)
> Application level events are fairly limited and consist mostly of
> events for child objects, however, as I write this I'm wondering if
> something in the WindowActivate event might work.
>
> Any one have a solution to this problem


--

Dave Peterson
 
Reply With Quote
 
Stephen Lloyd
Guest
Posts: n/a
 
      4th Nov 2009
On Nov 4, 8:21*am, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> Another option would be to give the routine that builds the toolbar/menu a
> shortcut key.
>
> Then tell the user that if they don't see the toolbar/menu to hit the shortcut
> key.
>
>
>
>
>
> Stephen Lloyd wrote:
>
> > I'm using Excel 2003. *I have an add-in that creates a menu in the
> > workbook open event and uses a class module to handle application
> > level events. *Call that xlApp.

>
> > In the xlApp_WorkbookBeforeClose() event I call code to remove the
> > menu. *This works fine if the user is removing the add-in in the
> > traditional sense, i.e. Tools>AddIns etc. *There is, however, an
> > undesired behavior when a user is attempting to close a workbook and
> > mistakenly clicks the close icon for the Excel Application.

>
> > If all workbooks were saved when the user misclicked, then tough luck,
> > restart excel. *If, however, there were unsaved changes in one or more
> > workbooks the user is graced with an opportunity to catch their
> > error. *A dialog box appears with options Yes, [Yes to all], No, and
> > Cancel. *If the user selects cancel, then none of the workbooks will
> > close.

>
> > The problem is that the BeforeClose() events for one or more workbooks
> > have already fired and the add-ins menu was removed.

>
> > So, I'm looking for a way to detect this situation and either avoid
> > deleting the menu or add the menu again.

>
> > In what order does Excel run the BeforeClose() events? *( I assume in
> > the index order of the workbooks)
> > Application level events are fairly limited and consist mostly of
> > events for child objects, however, as I write this I'm wondering if
> > something in the WindowActivate event might work.

>
> > Any one have a solution to this problem

>
> --
>
> Dave Peterson- Hide quoted text -
>
> - Show quoted text -


Thanks for the ideas gentleman. I'll post back when I've worked one
(or both out).
 
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
RE: Vista Start Menu Handling of Special Office Shortcuts Anders Bornholm Windows Vista General Discussion 0 1st Dec 2007 02:48 PM
Custom event handling for click of menu item. trialproduct2004@yahoo.com Microsoft Dot NET 2 23rd Feb 2007 07:08 PM
handling System Menu item click =?Utf-8?B?aXdkdTE1?= Microsoft VB .NET 1 27th Jul 2006 10:58 PM
Handling of userforms and popup menu's with dual monitor RB Smissaert Microsoft Excel Programming 0 9th Mar 2005 12:10 AM
MDI child windows event handling in menu item =?Utf-8?B?SW5kZXJqaXQgU2luZ2g=?= Microsoft Dot NET Compact Framework 0 22nd Mar 2004 09:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:57 PM.