title: Method Visible of Worksheet fails, but code runs successfully
body: <p>The following line:</p>
  
  <pre><code>ThisWorkbook.Sheets(vSheets(i, 1)).Visible = xlSheetVisible
  </code></pre>
  
  <p>generates the error:</p>
  
  <pre><code>Run-time error '-2147417848 (80010108)':
  
  Method 'Visible' of object '_Worksheet' failed
  </code></pre>
  
  <p>But if I click play in the debugger, execution finishes without a problem. So the line causes my code to go into the debugger. But it continues if I click play.</p>
  
  <p>Why?</p>
  
  <p><strong>EDIT1</strong>: Here is a screenshot where you can see that the debugger has stopped (with the error code written above) but you can also see in the immediate window that the Visible property exists.<img src="https://i.stack.imgur.com/KNcOU.jpg" alt="Note I have made some changes to the code to try to fix the problem since I originally posted the question, but I have the same error"></p>
  
  <p><strong>EDIT2</strong>: I tried setting wks as Variant instead of object and setting <code>wks.Visible=True</code> instead of <code>wks.visible = xlSheetVisible</code>. Neither of the changes helped. I still get the same error:</p>
  
  <p><img src="https://i.stack.imgur.com/C6aDG.jpg" alt="enter image description here"></p>