问题
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