title: Running VBA script causes excel to stop responding
body: <p>I have a VBA script that adds sheets to around 500 excel files.
  I had no problems running the VBA script and adding simple sheets, but when I try to add a sheet with VBA script in it and graphs and buttons, it works for a while and than freezes.</p>
  
  <p>Here is the code. I know it does not have error handling - any suggestions how to tackle this problem or maybe what is causing excel to freeze?</p>
  
  <pre><code>Sub FindOpenFiles()
  
  Const ForReading = 1
  Set oFSO = New FileSystemObject
  
  Dim txtStream As TextStream
  
  Dim FSO As Scripting.FileSystemObject, folder As Scripting.folder, file As Scripting.file, wb As Workbook, sh As Worksheet
  Dim directory As String
  
  'The path for the equipement list. - add the desired path for all equipement or desired value stream only.
  Set txtStream = oFSO.OpenTextFile("O:\SiteServices\Maintenance\Maintenance Support Folder\Maintenance Department Information\HTML for Knowledgebase\Excel for Knowledgebase\Equipement paths-all.txt", ForReading)
  
  Do Until txtStream.AtEndOfStream
      strNextLine = txtStream.ReadLine
      If strNextLine &lt;&gt; "" Then
  
      Set FSO = CreateObject("Scripting.FileSystemObject")
      Set folder = FSO.GetFolder(strNextLine)
  
  
      For Each file In folder.Files
          If Mid(file.Name, InStrRev(file.Name, ".") + 1) = "xls" Then
              Workbooks.Open strNextLine &amp; Application.PathSeparator &amp; file.Name
  
          Set wb = Workbooks("Equipment Further Documentation List.xls")
      For Each sh In Workbooks("Master File.xls").Worksheets
          sh.Copy After:=wb.Sheets(wb.Sheets.Count)
      Next sh
  
       ActiveWorkbook.Close SaveChanges:=True
       ActiveWorkbook.CheckCompatibility = False
  
          End If
  
  
      Next file
      End If
  
      Loop
  txtStream.Close
  
  End Sub
  </code></pre>