Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default How to disable all Excel Events and then re-activate them?

Hi all,

I have an .xls file in Excel 2002 format, in which it is used as a sort of
template in my group and then when new data is loaded onto it, it is saved
into under another name. It has two event calls in it:

SheetActivate()
SheetSelectionChange()

But I need to disable them load the new data in and then re-enable them. Is
there a way of doing this? Thanks for sharing your thoughts.


Ben

--

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 175
Default How to disable all Excel Events and then re-activate them?

application.enableevents=false
'do stuff here
application.enableevents=true

that should do it....

--
www.alignment-systems.com


"Ben" wrote:

Hi all,

I have an .xls file in Excel 2002 format, in which it is used as a sort of
template in my group and then when new data is loaded onto it, it is saved
into under another name. It has two event calls in it:

SheetActivate()
SheetSelectionChange()

But I need to disable them load the new data in and then re-enable them. Is
there a way of doing this? Thanks for sharing your thoughts.


Ben

--

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default How to disable all Excel Events and then re-activate them?

As has been pointed out, you should use EnableEvents. However, you
should also be aware of its limitations and its persistent nature. From
Monitoring events
http://www.tushar-mehta.com/excel/vb...L%20events.htm


An Excel specific trap: the EnableEvents property

The first problem with the EnableEvents property is that it applies only
to the Excel application. There are many objects that a developer uses
within the Excel environment that are not actually part of Excel object
heirarchy. Event associated with those objects will continue to be
raised. One of the most common objects is a userform! The userform is
part of the Office library and setting Excel=3Fs EnableEvents property to
False will have no effect on events raised by a userform or by objects
inside a userform. As it turns out there is no built-in method to block
userform events. For a workaround see chapter xx.

The other problem with the EnableEvents property is that it is
persistent in that it is not reset to True when user written code stops
executing. By contrast, if one programmatically set ScreenUpdating to
False, Excel will reset it to True when the VBA code stops executing.
Since this doesn=3Ft happen in the case of EnableEvents, it is imperative
that the developer reset it to True. This must happen with no ifs or
buts. The easiest way to do so is to always use an error trap with the
EnableEvents property. There are a few different ways to do this and
Code Sample 16 illustrates one.

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrXIT
Application.EnableEvents = False
With Target.Parent.Cells(1, 1)
.Value = .Value + 1
End With
ErrXIT:
Application.EnableEvents = True
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Multi-disciplinary business expertise
+ Technology skills
= Optimal solution to your business problem
Recipient Microsoft MVP award 2000-2005

In article ,
says...
Hi all,

I have an .xls file in Excel 2002 format, in which it is used as a sort of
template in my group and then when new data is loaded onto it, it is saved
into under another name. It has two event calls in it:

SheetActivate()
SheetSelectionChange()

But I need to disable them load the new data in and then re-enable them. Is
there a way of doing this? Thanks for sharing your thoughts.


Ben


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 175
Default How to disable all Excel Events and then re-activate them?

Hi Tushar,

"By contrast, if one programmatically set ScreenUpdating to
False, Excel will reset it to True when the VBA code stops executing. "

This is true in old versions of Excel.

In Excel 2002 and above it's not true (I think the switch happened in 2000 -
but I do not have a copy running on a box available to me right now to
check). Time for an edit????




--
www.alignment-systems.com


"Tushar Mehta" wrote:

As has been pointed out, you should use EnableEvents. However, you
should also be aware of its limitations and its persistent nature. From
Monitoring events
http://www.tushar-mehta.com/excel/vb...L%20events.htm


An Excel specific trap: the EnableEvents property

The first problem with the EnableEvents property is that it applies only
to the Excel application. There are many objects that a developer uses
within the Excel environment that are not actually part of Excel object
heirarchy. Event associated with those objects will continue to be
raised. One of the most common objects is a userform! The userform is
part of the Office library and setting Excel=3Fs EnableEvents property to
False will have no effect on events raised by a userform or by objects
inside a userform. As it turns out there is no built-in method to block
userform events. For a workaround see chapter xx.

The other problem with the EnableEvents property is that it is
persistent in that it is not reset to True when user written code stops
executing. By contrast, if one programmatically set ScreenUpdating to
False, Excel will reset it to True when the VBA code stops executing.
Since this doesn=3Ft happen in the case of EnableEvents, it is imperative
that the developer reset it to True. This must happen with no ifs or
buts. The easiest way to do so is to always use an error trap with the
EnableEvents property. There are a few different ways to do this and
Code Sample 16 illustrates one.

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrXIT
Application.EnableEvents = False
With Target.Parent.Cells(1, 1)
.Value = .Value + 1
End With
ErrXIT:
Application.EnableEvents = True
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Multi-disciplinary business expertise
+ Technology skills
= Optimal solution to your business problem
Recipient Microsoft MVP award 2000-2005

In article ,
says...
Hi all,

I have an .xls file in Excel 2002 format, in which it is used as a sort of
template in my group and then when new data is loaded onto it, it is saved
into under another name. It has two event calls in it:

SheetActivate()
SheetSelectionChange()

But I need to disable them load the new data in and then re-enable them. Is
there a way of doing this? Thanks for sharing your thoughts.


Ben



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
Events won't Disable! roadkill Excel Discussion (Misc queries) 2 April 26th 06 04:36 PM
Disable events Nigel Excel Programming 2 January 9th 06 06:40 AM
Deactive Activate Workbook Events - Add Menu jamiee Excel Programming 1 February 14th 04 08:43 PM
Disable Events wiwi Excel Programming 3 December 29th 03 04:53 PM
Disable Key Events Seth[_3_] Excel Programming 1 October 6th 03 10:28 PM


All times are GMT +1. The time now is 10:11 PM.

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

About Us

"It's about Microsoft Excel"