![]() |
enableevents in event codes
I hope this is not a dumb question!
in some event codes I see in the beginning the code statement application.enableevents=false and then at the end application.enableevents=true are these two statements (I understnad if one is there the otehr should be there) necessary and why? Thanks and regards. mine excel 2002(windows xp) |
enableevents in event codes
For example, if you have code inside a WorkSheetChange event that changes
the worksheet then it would trigger the WorkSheetChange code again: Private Sub Worksheet_Change(ByVal Target As Range) ActiveCell = ActiveCell + 1 End Sub So my question is, why doesn't this cause an endless loop? It stops when activecell value hits 227. Doug "R..VENKATARAMAN" wrote in message ... I hope this is not a dumb question! in some event codes I see in the beginning the code statement application.enableevents=false and then at the end application.enableevents=true are these two statements (I understnad if one is there the otehr should be there) necessary and why? Thanks and regards. mine excel 2002(windows xp) |
enableevents in event codes
In most case yes - it stops the macro retriggering itself In the following example the macro will run everytime any cell is changed even when the macro changes a1 Private Sub Worksheet_Change(ByVal Target As Range) range("a1").value=target.address & " Changed" End Sub In the follwing example the macro changing a1 does not trigger a fresh update to a1 Private Sub Worksheet_Change(ByVal Target As Range) application.enableevents=false range("a1").value=target.address & " Changed" application.enableevents=true End Sub -- mudraker ------------------------------------------------------------------------ mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473 View this thread: http://www.excelforum.com/showthread...hreadid=536685 |
All times are GMT +1. The time now is 04:50 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com