button - Excel 2010 - 禁用按钮

标签 button excel false-positive vba

我的电子表格上有 3 个不同的表单按钮。我想在按下其中一个时禁用其中两个。这可能吗?

在 C# 中,按钮可以是 true 或 false,但我在 VBA Excel 2010 中找不到任何这样的示例?

提前致谢

最佳答案

您无法禁用表单按钮。如果您想使用该功能,请使用 ActiveX 按钮。

但是还有一个替代方案。创建2个公共(public) bool 变量,然后在按钮1的单击事件中将变量设置为True或False。根据 bool 变量,其他 2 个按钮是否运行其代码。例如

Option Explicit

Dim enableB2 As Boolean, enableB3 As Boolean

Sub Button1_Click()
    If enableB2 = False Then
        enableB2 = True: enableB3 = True
    Else
        enableB2 = False: enableB3 = False
    End If

    '
    '~~> Rest of the code
    '
End Sub

Sub Button2_Click()
     If enableB2 = True Then
        '
        MsgBox "Hello You clicked Button 2"
        '
     End If
End Sub

Sub Button3_Click()
     If enableB3 = True Then
        '
        MsgBox "Hello You clicked Button 3"
        '
     End If
End Sub

关于button - Excel 2010 - 禁用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10700398/

相关文章:

wordpress - 将 "code"按钮添加到 wordpress tinyMCE

html - 如何为按钮添加声音效果?

javascript - jQuery - 单击按钮时增加计数器的值

excel - 如果两个单元格匹配,则从同一行中的第三个返回值,而与 Excel 中的顺序无关

ruby-on-rails - Rails 最佳实践误报未使用的方法

c++ - Win32 按钮外观

excel - Power Query - 根据单元格中电子邮件的出现创建和填充列 Email1、Email2 ...

sql-server - 事件任务 SSIS 中的自定义日志记录

cluster-analysis - 来自分类或聚类结果的 ROC 曲线

antivirus - 每次我们重新发布软件时,如何阻止杀毒软件误报?