Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default EnableEvents BeforeClose

Hi All,

I have a WorkBook_BeforeClose event procedure in which in a special case I
want to set Application.EnableEvents = false before a Thisworkbook.Close
statement in order to avoid re-calling the WorkBook_BeforeClose event
procedure. It works, but when next time opening the workbook
Application.EnableEvents = false, and I cannot automatically reset it to True
(e.g. in a WorkBook_open event procedure) because the False setting prevents
executing the WorkBook_open event.
How can I get out from this circulus vitiosus?

Thanks,
Stefi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default EnableEvents BeforeClose

Instead of disabling events, use a public variable

At the top of the thisworkbook module

Public bBlockEvents as Boolean

in the Beforeclose event at the top put in a line

if bBlockEvents then exit sub

then where you have the disable events statement replace it with

bBlockEvents = True

It should loose its value (become false) once the workbook is closed so you
won't have a problem on reopening.

--
Regards,
Tom Ogilvy


"Stefi" wrote in message
...
Hi All,

I have a WorkBook_BeforeClose event procedure in which in a special case I
want to set Application.EnableEvents = false before a Thisworkbook.Close
statement in order to avoid re-calling the WorkBook_BeforeClose event
procedure. It works, but when next time opening the workbook
Application.EnableEvents = false, and I cannot automatically reset it to

True
(e.g. in a WorkBook_open event procedure) because the False setting

prevents
executing the WorkBook_open event.
How can I get out from this circulus vitiosus?

Thanks,
Stefi



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default EnableEvents BeforeClose

Thank you Tom for your reply, it's a clever solution. Meanwhile I realized
that better not to step into the trouble than trying to get out of it. My
problem was caused by setting Cancel to True at the wrong place. Leaving it
False in the special branch of the routine made unnecessary to apply an extra
ThisWorkbook.Close statement because in this way the effect of clicking the
close button could prevail and after exiting the BeforeClose routin it closed
the workbook without manipulating Application.EnableEvents.

Regards,
Stefi


€˛Tom Ogilvy€¯ ezt Ć*rta:

Instead of disabling events, use a public variable

At the top of the thisworkbook module

Public bBlockEvents as Boolean

in the Beforeclose event at the top put in a line

if bBlockEvents then exit sub

then where you have the disable events statement replace it with

bBlockEvents = True

It should loose its value (become false) once the workbook is closed so you
won't have a problem on reopening.

--
Regards,
Tom Ogilvy


"Stefi" wrote in message
...
Hi All,

I have a WorkBook_BeforeClose event procedure in which in a special case I
want to set Application.EnableEvents = false before a Thisworkbook.Close
statement in order to avoid re-calling the WorkBook_BeforeClose event
procedure. It works, but when next time opening the workbook
Application.EnableEvents = false, and I cannot automatically reset it to

True
(e.g. in a WorkBook_open event procedure) because the False setting

prevents
executing the WorkBook_open event.
How can I get out from this circulus vitiosus?

Thanks,
Stefi




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application.EnableEvents DCPan Excel Worksheet Functions 3 October 18th 08 05:46 AM
application.EnableEvents nc Excel Discussion (Misc queries) 1 September 28th 05 04:00 PM
application.enableEvents jeffP Excel Programming 1 August 1st 04 03:12 PM
Application.EnableEvents Terry Excel Programming 2 April 2nd 04 08:25 PM
Stopping the use of enableevents Steven Revell[_3_] Excel Programming 3 November 21st 03 07:16 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"