2

我正在使用一个按钮来切换 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

4

1 回答 1

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以启用或禁用事件内的代码。

于 2013-05-11T23:51:05.713 回答