Make checkboes visible and invisible when a checkbox is ticked and unticked

别等时光非礼了梦想. 提交于 2020-06-28 07:04:41

问题


Heres the Code that I put in the module1 from Tim Williams

    Sub Tester()
        Dim isOn As Boolean

        With ActiveSheet
        Application.Caller = MuddyBoots
            isOn = (.CheckBoxes(Application.Caller).Value = xlOn)
            .CheckBoxes("TabletUser").Visible = isOn
            .CheckBoxes("WebUser").Visible = isOn
        End With
    End Sub

I have three checkboxes:

MuddyBoots TabletUser WebUser

When MuddyBoots is ticked I want TabletUser and WebUser to be visible and when MuddyBoots is unticked I want the two checkboxes TabletUser and WebUser to be invisible.

The code that works-ish is below:

    Public Sub TestCheckbox()
 Dim s As Shape

 Set s = ActiveSheet.Shapes("MuddyBoots")

  s.Select

  If Selection.Value = xlOn Then
     MsgBox "Checked"
     ActiveSheet.CheckBoxes("TabletUser").Visible = True
     ActiveSheet.CheckBoxes("WebUser").Visible = True
     'code here
 Else
     MsgBox "Not checked"
     ActiveSheet.CheckBoxes("WebUser").Visible = False
     ActiveSheet.CheckBoxes("TabletUser").Visible = False
     'code here
 End If

End Sub

This removes the two checkboxes if MuddyBoots is unticked after you ok the pop up message. If I comment out the msgbox line it doesn't work. Then I have to restart the VBA code.

These are form controls.

I also get the error message: Cannot run the macro New User Form Macro'!CheckBox17_Click'. The macro may not be available in this workbook or all macros may be disabled. I have changed the name of the checkboxs in the name box and have triple checked the checkboxes and they have the correct names...

I want to know how to get this functionality working without the popup messages and without the error please.


回答1:


Sub Tester()
    Dim isOn As Boolean

    With ActiveSheet
        'Application.Caller = name of calling shape
        isOn = (.CheckBoxes(Application.Caller).Value = xlOn)
        .CheckBoxes("TabletUser").Visible = isOn
        .CheckBoxes("WebUser").Visible = isOn
    End With

End Sub


来源:https://stackoverflow.com/questions/25874335/make-checkboes-visible-and-invisible-when-a-checkbox-is-ticked-and-unticked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!