title: VBA Loop directory removing (by sheet name) all sheets but one from each workbook
body: <p>I have previously posted on here about using VBA to loop through a folder and remove known passwords from each workbook therein. Thought I could use the same code and just insert code the removes all sheets except one (by reference to sheet name), but no such luck.</p>
  <p>Any VBA pros out there that can help?</p>
  <pre><code>Sub loop_sheets_del()
  
  Dim MyFile as String, str As String, MyDir = &quot;[directory]&quot;
  MyFile = Dir(MyDir &amp; &quot;*.xlsx&quot;)
  ChDir MyDir
  Application.ScreenUpdating = 0
  Application.DisplayAlerts = 0
  
  Do While Myfile &lt;&gt; &quot;&quot;
  Workbooks.Open (MyFile)
  If ws.Name &lt;&gt; &quot;name of sheet to keep&quot; Then
  ws.Delete
  End If
  
  Next ws (error indicates problem is here)
  
  ActiveWorkbook.Close True
  End With
  MyFile = Dir()
  Loop
  
  End Sub
  </code></pre>