how to catch these events?

N

NA_AB

Can we catch(or overload the event handler) the (Yes, No, Cancel) button
click events of Microsoft Excel when the user clicks the Close(X) button on
the top right corner of the ms excel workbook? Am basically building an excel
automation add-in to ms excel using c#.

Regards.
 
D

Dave Peterson

There is a workbook_BeforeClose event that will fire when the workbook is trying
to close--not just the X, but File|Close (or ctrl-w or ...)

If you're looking to monitor whenever a workbook closes, you can use an
application event.

You can read more about application events at Chip Pearson's site:
http://www.cpearson.com/excel/AppEvent.aspx
 
N

NA_AB

hey dave..exactly, i can use workbookbefore close, but, this event is fired
as soon as he clicks the (X) and "only after" the event is handled, the user
will see the pop-up which asks him.. "Do you want to save
changes..Yes..No..Cancel". I basically want to do two different things when
he chooses a Yes or a No. How can I ever know whether he has chosen a Yes/ a
No?(/ a Cancel)... Basically I need something like..
WorkbookAfterSave...which is not present in the workbookevents.

Regards.
 
D

Dave Peterson

You could provide your own macro (and a way to run it) that does the work.

Disable the workbook_beforeclose event or at the application level.

Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = True
MsgBox "Please use my method to close this workbook"
End Sub

I think Jan Karel Pieterse wrote a very intricate way to catch this kind of
stuff...

I couldn't find it, but you may want to look:
http://www.jkp-ads.com/

Good luck.
 
N

NA_AB

hey Dave...

When you said this:
MsgBox "Please use my method to close this workbook"

Do you mean to put a restriction on the user, thus, not allowing him to
close the workbook in a way he wishes to?

Also, am using C# .net... your code seems to be a vb code.. and, am not
allowed to write any macros, all i have is my C# project that has a refernce
to the ms excel as 'MyApplication'..

Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top