title: How to find specific text in text file, and add additional text in the following line in excel VBA
body: <p>I need to open a txt file, find an specific string, write several lines right below it, save the resulting file and close it. This is what I have so far:</p>
  
  <pre><code>Sub EditMyTXT()
  
  Dim FileNum As Integer
  Dim DataLine As String
  
  FileNum = FreeFile()
  Open "E:\Host.txt" For Input As #FileNum
  
  While Not EOF(FileNum)
      Line Input #FileNum, DataLine
          If DataLine = "TextToFind" Then
               move to the next line
               write text "TextToWriteBelow TextToFind"
               move to the next line
               write text "MoreTextToWriteBelow"
          Else: End If
  Wend
  
   Save FileNum
   Close FileNum
  
  End Sub
  </code></pre>
  
  <p>I can't find a way to open a txt file in a mode that would allow me to read an write to it. Any ideas, suggestions?</p>