我使用以下代码自动生成一个新复选框并将单元格链接到它:
sub
我想创建另一个.LinkedCell
,当选中复选框(蓝色)或未选中(红色)时,应更改复选框的.LinkedCell
单元格的背景颜色。我将在工作表中有大约200个复选框。
有没有办法获取/返回当前已选中/未选中复选框的sub
地址,以便.LinkedCell
可以更改该单元格的背景颜色?
例如,假设.LinkedCell
是最初放置复选框的单元格。这将是每个复选框的初始状态:
这将是用户检查/取消选中checbox后的结果:
直到现在我使用此代码更改复选框本身的背景颜色。但我不希望这样,我想改变Sub SetMacro()
Dim cb
For Each cb In ActiveSheet.CheckBoxes
If cb.OnAction = "" Then cb.OnAction = "CheckedUnchecked"
Next cb
End Sub
的颜色。
Sub CheckedUnchecked()
With ActiveSheet.Shapes(Application.Caller).DrawingObject
If .Value = 1 Then
.Interior.ColorIndex = 5
Else
.Interior.ColorIndex = 3
End If
End With
End Sub
和
If gpio Is Nothing Then
gpio = GpioController.GetDefault.openpin(LED_PIN)
end if
答案 0 :(得分:2)
您可以使用以下内容替换CheckedUnchecked代码:
Sub CheckedUnchecked()
With ActiveSheet.Range(ActiveSheet.CheckBoxes(Application.Caller).LinkedCell)
If .Value Then
.Interior.ColorIndex = 5
Else
.Interior.ColorIndex = 3
End If
End With
End Sub