title: Trying to delete all sheets in a workbook, then add other sheets in with VBA
body: <p>I keep running into errors trying to delete most sheets in a workbook, then add them back in.</p>
  
  <p>I cannot delete all sheets in a workbook; at least one sheet needs to be there. Fine. So I first create a sheet called <code>TempSheet</code>.</p>
  
  <pre><code>targetWorkbook = ActiveWorkbook.Name
  '/* ...more code... */
  Application.Workbooks(targetWorkbook).Activate
  Application.Workbooks(targetWorkbook).Worksheets.Add.Name = "TempSheet"
  </code></pre>
  
  <p>So now, I want to delete all of the sheets besides <code>TempSheet</code> in my workbook. So I'm trying to do this:</p>
  
  <pre><code>For Each ws1 In Application.Workbooks(targetWorkbook).Worksheets
      If ws1.Name &lt;&gt; "TempSheet" Then
          Workbooks(targetWorkbook).Sheets(ws1.Name).Delete '/* Line X. */
      End If
  Next
  </code></pre>
  
  <p>When I step through my code and get to <code>Line X</code>, I get the error <code>Can't enter break mode at this time</code>. I've tried replacing all the code on <code>Line X</code> with just <code>ws1.Delete</code>, I get the same message. I would like to at least step through the code so I can see the sheets being deleted.</p>
  
  <p>The other part of my code is such that I would like to take all of the sheets from another workbook and place them in the first workbook where I deleted all of the sheets from above. My code is below:</p>
  
  <pre><code>Application.Workbooks("OtherWorkbook").Activate '/* Line Y. */
  For Each ws2 In Application.Workbooks(sheetsWorkbook).Worksheets
      ws2.Copy After:=Workbooks(targetWorkbook).Sheets(ws1.Name)
  Next
  </code></pre>
  
  <p>I put a breakpoint on <code>Line Y</code>, and after I get the <code>Can't enter break mode at this time</code> error, I hit the <code>Continue</code> button. Instead of stopping at the break point, I get the error <code>Run-time error '424'. Object required</code>, which doesn't show me which line it is referring to and doesn't let me debug (the button is grey'd out and the only button I can select is <code>end</code>).</p>
  
  <p>Any suggestions on how I can achieve this?</p>