Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Custom menus clean-up


Hi Peter,

An Excel add-in (XLA) does not have an equivalent event to the
OnDisconnection or OnBeginShutdown events for a COM Add-in.

As such I believe that the best solution in this situation would be to add
your own custom code to the WorkBook_BeforeClose event that would check for
any workbooks that haven't been saved, and then display a custom message
box that would contain the Yes, No, and Cancel options as the dialog
displayed by Excel.

This would allow the code in your add-in to handle a scenario where the
user would click Cancel so that the menus would not be removed.

I have included sample code below to demonstrate what this code might look
like. Please note that the code below is not complete and you would need
to customize this for your add-in.

Sample Code
=====================
Private Sub Workbook_BeforeClose(Cancel As Boolean)

Dim wbk As Workbook


For Each wbk In Application.Workbooks

If wbk.Saved = False Then

CloseWorkbooks wbk, Cancel

End If

Next

End Sub


Sub CloseWorkbooks(wbk As Workbook, ByRef Cancel As Boolean)

Select Case MsgBox("Do you want to save the changes you made to '" &
wbk.Name & "'?", _
vbExclamation + vbYesNoCancel + vbDefaultButton1, "Microsoft Excel")

Case vbYes

If wbk.Path < "" Then

wbk.Save

Else

wbk.Activate

If Application.Dialogs(xlDialogSaveAs).Show = False Then

CloseWorkbooks wbk, Cancel

Else

Exit Sub

End If

End If

Case vbNo

wbk.Saved = True

Case vbCancel

Cancel = True

Exit Sub

End Select

End Sub
====================================

I hope this helps!

If you have any questions please let me know via the posting.

Regards,

Ken Laws
Microsoft Support


This posting is provided "AS IS" with no warranties, and confers no rights.

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
Please Help Me with Custom menus Mr BT Excel Worksheet Functions 7 July 4th 06 05:15 PM
Sharing Custom Menus blriggscg Excel Discussion (Misc queries) 1 October 25th 05 05:42 PM
Custom Menus and Macros Dave Peterson Excel Discussion (Misc queries) 4 January 25th 05 11:27 PM
Custom menus Lee Excel Programming 4 November 12th 03 11:53 PM
Custom Menus Andy Wiggins[_2_] Excel Programming 0 September 19th 03 06:10 AM


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