VBA Worksheet change event bypass?

后端 未结 4 413
花落未央
花落未央 2020-12-03 11:02

I am fixing a spreadsheet. The programmer made a macro for each sheet to fire when the sheet is changed. This is good because it colour co-ordinates the sheet details when n

4条回答
  •  再見小時候
    2020-12-03 11:26

    I think you want the EnableEvents property of the Application object. When you set EnableEvents to False, then nothing your code does will trigger any events and none of the other event code will run. If, for example, your code changes a cell it would normally trigger the Change event or the SheetChange event. However, if you structure it like this

    Application.EnableEvents = False
        Sheet1.Range("A1").Value = "new"
    Application.EnableEvents = True
    

    then changing A1 won't trigger any events.

    Sometimes it's beneficial to have your code trigger event code and sometimes it's not. Use EnableEvents when you want to prevent it.

提交回复
热议问题