ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Setting Application.EnableEvents=True after Thisworkbook.Close call (https://www.excelbanter.com/excel-programming/371864-setting-application-enableevents%3Dtrue-after-thisworkbook-close-call.html)

John Fuller

Setting Application.EnableEvents=True after Thisworkbook.Close call
 
Is there anyway to get excel to re-enable application events after i
close a workbook.

Right now I have in some code:

Application.EnableEvents = False
ThisWorkbook.Close
Application.EnableEvents = True

However, the enableevents never gets set back to true as the sub stops
running when excel closes. Any help is appreciated.


Bernie Deitrick

Setting Application.EnableEvents=True after Thisworkbook.Close call
 
John,

I'm assuming that you don't want to run the Workbook_BeforeClose event: include code like this at
the top of the Workbook_BeforeClose event:

If boolDontRun Then Exit Sub

Declare a global variable in a standard codemodule:

Public boolDontRun As Boolean

Then instead of

Application.EnableEvents = False
ThisWorkbook.Close
Application.EnableEvents = True

Use

boolDontRun = True
ThisWorkbook.Close

HTH,
Bernie
MS Excel MVP


"John Fuller" wrote in message
ups.com...
Is there anyway to get excel to re-enable application events after i
close a workbook.

Right now I have in some code:

Application.EnableEvents = False
ThisWorkbook.Close
Application.EnableEvents = True

However, the enableevents never gets set back to true as the sub stops
running when excel closes. Any help is appreciated.




John Fuller

Setting Application.EnableEvents=True after Thisworkbook.Close call
 
That's what I have done, was just hoping there was a way of avoiding
the global variable (just a rule I have, the always seem to cause
problems). Thanks though.

Bernie Deitrick wrote:
John,

I'm assuming that you don't want to run the Workbook_BeforeClose event: include code like this at
the top of the Workbook_BeforeClose event:

If boolDontRun Then Exit Sub

Declare a global variable in a standard codemodule:

Public boolDontRun As Boolean

Then instead of

Application.EnableEvents = False
ThisWorkbook.Close
Application.EnableEvents = True

Use

boolDontRun = True
ThisWorkbook.Close

HTH,
Bernie
MS Excel MVP


"John Fuller" wrote in message
ups.com...
Is there anyway to get excel to re-enable application events after i
close a workbook.

Right now I have in some code:

Application.EnableEvents = False
ThisWorkbook.Close
Application.EnableEvents = True

However, the enableevents never gets set back to true as the sub stops
running when excel closes. Any help is appreciated.



Murali

Setting Application.EnableEvents=True after Thisworkbook.Close call
 
I think this may help u

write this code in the workbook_windowdeactivate event
Application.EnableEvents = True

regards
murali




John Fuller wrote:
Is there anyway to get excel to re-enable application events after i
close a workbook.

Right now I have in some code:

Application.EnableEvents = False
ThisWorkbook.Close
Application.EnableEvents = True

However, the enableevents never gets set back to true as the sub stops
running when excel closes. Any help is appreciated.




All times are GMT +1. The time now is 04:14 AM.

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