Run Procedure when Excel closes

  • Thread starter Thread starter Tod
  • Start date Start date
T

Tod

Hi All,

I have some code that will test my Error Trapping setting
and, if it is set to Break on All Errors, sets it to Break
on Unhandled Errors. I would like for it to run when I
close Excel. Is there an event I can harness for this?

Also, it would be even better if that event also knew if
Excel was visible. If Excel is not visible then I'm
running it via a script and do not want that code to run.

tod
 
Tod,

The BeforeClose event. Here is some code top test whether the application is
visible or not in that event, which should get you started

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Application.Visible = True Then
MsgBox "Visible"
Else
MsgBox "Not visible"
End If
End Sub
 
Thanx. Actually I want the code to run when Excel closes
regardless of any workbooks that I'm closing.
 
Tod,

Put the code in your Personal.xls and make sure it is in the ThisWorkbook
module.

When Excel closes, it closes your Personal.xls and should fire the event.
 
Tod,

Of course you do, I knew you did and I know there is no quit event, but
still got it wrong!

IIRC, suggested ways of doing this usually suggest that you have you code
open a workbook and hide it. Put the code in that workbook's Before_Close
event. Inelegant, but it could work. Workbook doesn't have a Hidden or
Visible property, but Window does, so use that.
 

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

Back
Top