禁用特定事件

时间:2013-05-11 23:19:24

标签: excel

我正在使用按钮来切换Application.EnableEvents:

Sub Button1_Click()
If ActiveSheet.Shapes("Button 1").TextFrame.Characters.Text = "Disable Events" Then
    ActiveSheet.Shapes("Button 1").TextFrame.Characters.Text = "Enable Events"
    Application.EnableEvents = False
Else
    ActiveSheet.Shapes("Button 1").TextFrame.Characters.Text = "Disable Events"
    Application.EnableEvents = True
End If
End Sub

如何在不停用SelectionChange的情况下停用Change

1 个答案:

答案 0 :(得分:4)

不完全确定您为什么要禁用SelectionChange或将要执行的操作?

如果您在该部分中有代码,则可以将其包装在if语句中。

' Insert the following code into a new module: Module1
Public SelectionChange_Enabled As Boolean

' Example of your Worksheet_SelectionChange event's code
Public Sub Worksheet_SelectionChange(ByVal Target As Range)
    If SelectionChange_Enabled = True Then
    ' Your code
    End If
End Sub

您可以更改SelectionChange_Enabled的值以启用或禁用事件内的代码。