title: Running macro (to assign linked cells to all checkboxes on given sheets) on all files in a folder
body: <p>I am trying to reassign all the linked cells for checkboxes on three given worksheets in a large collection of workbooks.</p>
  
  <p>The macro I have works successfully on any book I have open:</p>
  
  <pre><code>Sub CheckBoxesControl()
  
  On Error Resume Next
  
      Dim i As Long
  
      For i = 1 To 400
          Sheet4.CheckBoxes("Check Box " &amp; i).LinkedCell = "ChkBoxOutput!AA" &amp; i
          Sheet21.CheckBoxes("Check Box " &amp; i).LinkedCell = "ChkBoxOutput!AB" &amp; i
          Sheet22.CheckBoxes("Check Box " &amp; i).LinkedCell = "ChkBoxOutput!AC" &amp; i
  
      Next i
  
  End Sub
  </code></pre>
  
  <p>However I want to run this across a large number of sheets, so I tried the following:</p>
  
  <pre><code>Sub CheckBoxesControl()
  
  On Error Resume Next
      Dim path As String
      Dim file As String
      Dim wkbk As Workbook
      Dim i As Long
  
  
      Application.ScreenUpdating = False
      Application.DisplayAlerts = False
  
      path = "C:\file\path\"
      file = Dir(path)
  
      Do While Not file = ""
          Workbooks.Open (path &amp; file)
          Set wkbk = ActiveWorkbook
  
      For i = 1 To 400
          Sheet4.CheckBoxes("Check Box " &amp; i).LinkedCell = "ChkBoxOutput!AA" &amp; i
          Sheet21.CheckBoxes("Check Box " &amp; i).LinkedCell = "ChkBoxOutput!AB" &amp; i
          Sheet22.CheckBoxes("Check Box " &amp; i).LinkedCell = "ChkBoxOutput!AC" &amp; i
  
      Next i
  
      wkbk.Save
      wkbk.Close
      file = Dir
      Loop
  
  End Sub
  </code></pre>
  
  <p>The macro certainly opens and closes each file, and runs without error, but it is not having the desired affect.</p>
  
  <p>It only changes the check boxes for the sheet I run the macro from still (despite apparently opening saving and closing all the others).</p>
  
  <p>Am I failing to correctly set the active workbook?</p>
  
  <p><strong>EDIT 1: Suggested fix (failed)</strong></p>
  
  <p>Method suggested in comments (proved unsuccessful):</p>
  
  <pre><code>Sub CheckBoxesControl()
  
  On Error Resume Next
      Dim path As String
      Dim file As String
      Dim wkbk As Workbook
      Dim i As Long
  
  
      Application.ScreenUpdating = False
      Application.DisplayAlerts = False
  
      path = "C:\file\path\"
      file = Dir(path)
  
      Do While Not file = ""
  
          Set wkbk = Workbooks.Open(path &amp; file)
      For i = 1 To 400
          wkbk.Sheet4.CheckBoxes("Check Box " &amp; i).LinkedCell = "ChkBoxOutput!AA" &amp; i
          wkbk.Sheet21.CheckBoxes("Check Box " &amp; i).LinkedCell = "ChkBoxOutput!AB" &amp; i
          wkbk.Sheet22.CheckBoxes("Check Box " &amp; i).LinkedCell = "ChkBoxOutput!AC" &amp; i
          If Err.Number &lt;&gt; 0 Then
  
          End If
      Next i
  
      wkbk.Save
      wkbk.Close
      file = Dir
      Loop
  
  End Sub
  </code></pre>
  
  <p><strong>EDIT 2: REMOVING ON ERROR RESUME NEXT</strong></p>
  
  <p>Suggestedion to remove the error ignoring has illustrated the following: when the macro runs an error:</p>
  
  <p>Run-time error 1004
  The item with the specific name wasn't found.</p>
  
  <p>Debugging this error highlights:</p>
  
  <pre><code>Sheet4.CheckBoxes("Check Box " &amp; i).LinkedCell = "ChkBoxOutput!AA" &amp; i
  </code></pre>
  
  <p>I believe I realise what this issue is: I'm using a "go between 1 and 400" loop to ensure I catch all the checkboxes on each page, but there isn't a checkbox for each one of those instances, (checkbox1 doesn't exist for example, on all pages - notably not on sheet 4)</p>
  
  <p>I remember now this is why I had On error resume next there in the first place... but I need "next" to be the next "i" in the loop, not the next expression completely.</p>