Importer les 5 dernières lignes d'un fichier texte

J'ai un fichier texte très long et j'ai besoin d'en récupérer seulement les 5 dernières lignes.

Utilise cette macro:

sub test()
 
 Dim file_name As String
 Dim file_length As Long
 Dim fnum As Integer
 Dim bytes() As Byte
 Dim txt As String
 Dim i As Integer
 
  file_name = "F:DocFloessai.txt"
  file_length = FileLen(file_name)
  f2 = 1000
  f1 = file_length - f2
 
  fnum = FreeFile
 
  Open file_name For Binary As #fnum
 
  ReDim bytes(1 To f2)
  Get #fnum, f1 + 1, bytes
  Close fnum
 
  ' Afficher résultats
  For i = 1 To f2
    txt = txt & Chr(Format$(bytes(i)))
  Next i
  Debug.Print txt
 
 end sub

Auteur :

Mots clefs associés à cette page : ,