Setting Application.EnableEvents=True after Thisworkbook.Close call

  • Thread starter Thread starter John Fuller
  • Start date Start date
J

John Fuller

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,

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
 
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.
 
I think this may help u

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

regards
murali
 

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