title: Export Data from Excel to Text File
body: <p>i need help plz </p>
  
  <p>I have a excel file and I want to export all data from it to a text file.</p>
  
  <p>This the source code:</p>
  
  <hr>
  
  <pre><code>Sub ExceltoText()
  
      Dim FileName, sLine, Deliminator, x, y, z As String
      Dim LastCol, LastRow, FileNumber As Integer
  
  
      FileName = "C:\Users\Administrateur\Desktop\App vba\ExcToTxt.txt"
  
      Deliminator = "|"
      x = "$|0|Les Données de SALARIES"
      y = "=|0|Les Données de SALARIES"
      z = "=|1|SALARIES|"
  
      LastCol = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
      LastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
      FileNumber = FreeFile
  
      Open FileName For Output As FileNumber
  
      For i = 1 To LastRow
          For j = 1 To LastCol
              If j = LastCol Then
                  sLine = z &amp; sLine &amp; Cells(i, j).Value
              Else
                  sLine = sLine &amp; Cells(i, j).Value &amp; Deliminator
              End If
          Next j
          If i = 1 Then i = 2
          Print #FileNumber, sLine
          sLine = ""
      Next i
      Close #FileNumber
      MsgBox "File generated"
  End Sub
  </code></pre>
  
  <hr>
  
  <p>In the result I got this text file in that format:</p>
  
  <hr>
  
  <pre><code>=|1|SALARIES|PSA_etablissement|PSA_SALARIE|
  
  =|1|SALARIES|001|10635|
  
  =|1|SALARIES|001|10637|
  </code></pre>
  
  <p>But I want my text file to be like that:</p>
  
  <hr>
  
  <pre><code>$=|1|SALARIES|PSA_etablissement|PSA_SALARIE|
  
  =|1|SALARIES|001|10635|
  
  =|1|SALARIES|001|10637|
  </code></pre>
  
  <p>and I want to add those lines in the beginning of the text file: </p>
  
  <hr>
  
  <pre><code>$|0|Les Données de SALARIES
  
  =|0|Les Données de SALARIES
  </code></pre>