vba - 跳过复选框 Click() 函数 [VBA]

标签 vba excel checkbox

我有用户表单,我用它来显示项目的状态。这些项目经历了一个 3 阶段的过程。对于每个流程,都有一个复选框,一旦项目通过了一个阶段,就可以选中该复选框。单击时,会向用户显示“您确定吗?”迅速的。如果用户选择"is"(vbYes),则该过程在 SQL 表中被标记为已完成。

当我想显示已经通过一个或多个阶段的项目时,就会出现问题。初始化表单时,我将相关阶段的复选框的值设置为“True”。但是,这会激活复选框的单击功能,这不是预期的。有没有办法跳过这个?

代码示例(不是实际代码)

Private Sub UserForm_Initialize()
    'Check check boxes, where stages are completed
    If stage_1_completed Then
        chkStage1.value = True
    End If
    If stage_2_completed Then
        chkStage2.value = True
    End If
    If stage_3_completed Then
        chkStage1.value = True
    End If

End Sub

'This part should only run, if the check box is clicked manually
Private Sub chkStage1_Click()
    If chkStage1.value = True Then
        'Prompt user if sure?
        promptAnswer = MsgBox("Are you sure?", vbYesNo, "Continue?")

        'Mark stage 1 as processed if yes
        If promptAnswer = vbYes Then
            set_stage_completed (1)
        End If

    End If
End Sub

最佳答案

一种方法是使用变量来存储状态:

Public EnableEvents As Boolean

Private Sub UserForm_Initialize()
    Me.EnableEvents = False

    ''
    ' initialize form here
    ''

    Me.EnableEvents = True
End Sub

Private Sub chkStage1_Click()
    If Not Me.EnableEvents Then Exit Sub

    ''
    ' handle event here
    ''
End Sub

关于vba - 跳过复选框 Click() 函数 [VBA],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36059421/

相关文章:

python - 将excel转换为csv后无法读取head

javascript - 添加所有输入 rel 的总和。适用于复选框,直到添加了选择输入

VBA MapNetworkDrive 到带有 Windows 凭据的服务器

vba - 将 Word Doc 另存为 PDF 时出现问题 "This is not a valid file name"

vba - 如何避免 Excel 本地化对象名称和破坏宏?

excel - 有没有办法在 Excel 中的 VBA 格式条件内编写与本地语言无关的公式?

excel - 使用值定义跨模块变量

jquery - 使用 jQuery Mobile 将水平复选框宽度拉伸(stretch)到 100%

javascript - 能够在渲染 Highcharts 后显示检查系列的标签

vba - VarType 用于用户定义类型