2016-12-17 7 views
0

別のチェックボックス「print1」がチェックされている場合、スプレッドシート上の「print」という名前のすべてのチェックボックスを選択/選択解除しようとしています。vbaスプレッドシートの名前がxのすべてのチェックボックスを選択/選択解除しますか?

私は、各ループの一部として次のコードを使用して自分のチェックボックスを作成しています。

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というマクロが割り当てられています。ユーザーがこのチェックボックスをオンまたはオフにしたときにマクロがトリガーされ、 '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 

何らかの理由で、私のチェックボックスの1つだけがチェックされています。私は何が間違っているのか分からない、誰かが私を見せてくれますか? for eachループ変化

答えて

0

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 Sub 
+0

を、これは単に、すべてのチェックボックスをチェックします。私はそれらのチェックボックスを 'print'という名前でチェックしたいだけです。 –

関連する問題