通过CommandButton取消选中整个工作簿中的所有复选框 [英] Uncheck all checkboxes across entire workbook via CommandButton

查看:253
本文介绍了通过CommandButton取消选中整个工作簿中的所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个代码,取消选中名为CheckBox1的所有工作簿中的所有工作簿的复选框。我现在的代码不能正常工作,我不知道为什么 - 它只适用于活动工作表。

I would like to have a code that unchecks all checkboxes named "CheckBox1" for all sheets across the workbook. My current code unfortunately doesn't work, and I'm not sure why - it only works for the active sheet.

Private Sub CommandButton1_Click()

    Dim Sheet As Worksheet
    For Each Sheet In ThisWorkbook.Worksheets

        Select Case CheckBox1.Value
        Case True: CheckBox1.Value = False
        End Select  
    Next
End Sub


推荐答案

此代码遍历所有工作表(除了 Sheet100 OtherSheet 复选框中选中 code> CheckBox1

This code iterates through all sheets (except sheets named Sheet100 and OtherSheet) and unchecks all your ActiveX checkboxes named CheckBox1

Sub uncheck_boxes()

    Dim ws As Worksheet
    Dim xbox As OLEObject
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Sheet100" And ws.Name <> "OtherSheet" Then
            For Each xbox In ws.OLEObjects
                ws.OLEObjects("CheckBox1").Object.Value = False
            Next
        End If
    Next
End Sub

要取消选中所有 ActiveX 复选框忽略所使用的名称

To uncheck all ActiveX checkboxes in all sheets disregarding the names used

Sub uncheck_all_ActiveX_checkboxes()

    Dim ws As Worksheet
    Dim xbox As OLEObject
    For Each ws In ThisWorkbook.Worksheets
        For Each xbox In ws.OLEObjects
            ws.OLEObjects(xbox.Name).Object.Value = False
        Next
    Next
End Sub

取消选中电子表格中所有 表单控制复选框

To uncheck all Form Control checkboxes on a spreadsheet use

Sub uncheck_forms_checkboxes()

    Dim ws As Worksheet
    Dim xshape As Shape
    For Each ws In ThisWorkbook.Worksheets
        For Each xshape In ws.Shapes
            If xshape.Type = msoFormControl Then
                xshape.ControlFormat.Value = False
            End If
        Next
    Next
End Sub

这篇关于通过CommandButton取消选中整个工作簿中的所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆