如果选中了另一个复选框“print1”,我将尝试选择/取消选中电子表格上的所有名称为“print”的复选框。
我正在创建我的复选框,使用以下代码作为每个循环的一部分。
For Each objFile In objFolder.Files
If DatePart("ww", objFile.DateCreated, vbMonday, vbFirstFourDays) = Range("H7").Value Then
'print file PG
Cells(i + 13, 1) = Range("T7").Value
'print file Month
Cells(i + 13, 5) = Range("H7").Value
'print file Year
Cells(i + 13, 9) = Range("B7").Value
'print file name
Cells(i + 13, 13) = objFile.Name
'print file path
Cells(i + 13, 18) = "=hyperlink(""" & objFile.Path & """)"
'add action box 1
ActiveSheet.CheckBoxes.Add(Cells(i + 13, 27).Left, Cells(i + 13, 27).Top, Cells(i + 13, 27).Width, Cells(i + 13, 27).Height).Select
With Selection
.Name = "print"
.Caption = ""
.Value = xlOff '
.LinkedCell = Cells(i + 13, 27)
.Display3DShading = False
End With这将根据需要创建名称为“print”的复选框。
我还有一个唯一的复选框,名为“print1 1”。此复选框有一个分配给它的宏,名为set_print。当用户选中/取消选中此复选框时,宏应该触发,并且应该选中/取消选中其他所有名为“print”的复选框。为此,我使用以下代码:
Sub set_print()
If ActiveSheet.CheckBoxes("print").Value <> xlOn Then
ActiveSheet.CheckBoxes.Value = xlOn
ActiveSheet.Shapes("Search1").TextFrame.Characters.Text = "Print"
Else
ActiveSheet.CheckBoxes("print").Value = xlOff
ActiveSheet.Shapes("Search1").TextFrame.Characters.Text = "Search"
End If
End Sub出于某种原因,只选中了我的一个复选框。我不知道我做错了什么,有人能给我看看吗?
发布于 2016-12-17 22:57:02
在for each循环更改中:
With Selection
.Name = "print"至:
With Selection
.Name = "print" & i然后将Sub set_print()更改如下:
Sub set_print()
With ActiveSheet
If .CheckBoxes("print1").Value <> xlOn Then
CheckThem xlOn
.Shapes("Search1").TextFrame.Characters.Text = "Print"
Else
CheckThem xlOff
.Shapes("Search1").TextFrame.Characters.Text = "Search"
End If
End With
End Sub
Sub CheckThem(xlOnOff As Long)
Dim chkBx As CheckBox
With ActiveSheet
For Each chkBx In .CheckBoxes
If Left(chkBx.Name, 5) = "print" Then chkBx.Value = xlOnOff
Next
End With
End Subhttps://stackoverflow.com/questions/41203605
复制相似问题