[英]Get Values of all Check Boxes in Excel using VBA
我使用以下代碼將多個復選框添加到excel表programaticaly:
With ActiveSheet.CheckBoxes.Add(rCell.Left, rCell.Top, rCell.Width, rCell.Height)
.Interior.ColorIndex = xlNone
.Caption = ""
End With
現在我需要一個代碼來解析工作表中存在的所有復選框並獲取它們的值(true或false)以及它們所在的單元格。 這該怎么做?
謝謝...
Sub Add_CheckBoxes()
With ActiveSheet.CheckBoxes.Add(ActiveCell.Left, ActiveCell.Top, ActiveCell.Width, ActiveCell.Height)
.Interior.ColorIndex = xlNone
.Caption = ""
End With
For Each chk In ActiveSheet.CheckBoxes
If chk Then MsgBox "Checked"
Next
End Sub
添加復選框后,您可以像這樣循環遍歷它們:
Sub Checkbox_Test()
Dim chk As CheckBox
Dim cell As Range
For Each chk In ActiveSheet.CheckBoxes
If chk.Value = Checked Then '1 is true, but the constant
Set cell = chk.TopLeftCell ' "Checked" avoids "magic numbers".
'do whatever with cell
MsgBox cell.Address
End If
Next chk
結束子
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.