【发布时间】:2017-05-03 09:13:13
【问题描述】:
如果选中了另一个复选框“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
这会根据需要创建多个名称为“打印”的复选框。
我还有一个名为“print1”的独特复选框。这个复选框有一个分配给它的宏,称为 set_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
由于某种原因,我只选中了一个复选框。我不确定我做错了什么,请有人告诉我吗?
【问题讨论】: