title: VBA: How to read and copy specific string from all txt files in a folder
body: <p>I found a resource to find specific strings at the following link: <a href="https://www.excel-easy.com/vba/examples/read-data-from-text-file.html" rel="nofollow noreferrer">https://www.excel-easy.com/vba/examples/read-data-from-text-file.html</a></p>
  
  <p>How could I apply this to all the .txt files in a folder?</p>
  
  <pre><code>Sub READLINES()
  Dim myFile As String, text As String, textline As String, posFood As Integer
  'myFile = "C\FOLDER\TEST.txt"
  myFile = Application.GetOpenFilename()
  
  Open myFile For Input As #1
  
  Do Until EOF(1)
      Line Input #1, textline
      text = text &amp; textline
  Loop
  Close #1
  
  posFood = InStr(text, "BACON")
  Range("A1").Value = Mid(text, posFood + 7, 3) 'should return YUM
  
  End Sub
  </code></pre>