ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run Procedure when Excel closes (https://www.excelbanter.com/excel-programming/276847-run-procedure-when-excel-closes.html)

Tod

Run Procedure when Excel closes
 
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

Bob Phillips[_5_]

Run Procedure when Excel closes
 
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


--

HTH

Bob Phillips

"Tod" wrote in message
...
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

Run Procedure when Excel closes
 
Thanx. Actually I want the code to run when Excel closes
regardless of any workbooks that I'm closing.

-----Original Message-----
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


--

HTH

Bob Phillips

"Tod" wrote in message
...
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



.


steve

Run Procedure when Excel closes
 
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.

--
sb
"Tod" wrote in message
...
Thanx. Actually I want the code to run when Excel closes
regardless of any workbooks that I'm closing.

-----Original Message-----
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


--

HTH

Bob Phillips

"Tod" wrote in message
...
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



.




Bob Phillips[_5_]

Run Procedure when Excel closes
 
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.

--

HTH

Bob Phillips

"Tod" wrote in message
...
Thanx. Actually I want the code to run when Excel closes
regardless of any workbooks that I'm closing.

-----Original Message-----
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


--

HTH

Bob Phillips

"Tod" wrote in message
...
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



.





All times are GMT +1. The time now is 12:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com