Afficher un message
Vieux 05/12/2007, 17h44   #4 (permalink)
MichelXld
XLDnaute Barbatruc
 
Date d'inscription: février 2005
Messages: 3 569
Par défaut Re : Ouvrir fichier avc bloc-notes via Excel

bonsoir Hervé, bonsoir cher Pascal


Pour supprimer les lignes, tu peux tester

Code:
Option Explicit
Option Base 1

Sub SuppressionLignes()
    Dim objCol As New Collection
    Dim x As Integer, i As Integer
    Dim strLigne As String, Fichier As String
    Dim Tableau As Variant
    
    'Définit les lignes à supprimer, par
    'ordre décroissant impérativement !
    Tableau = Array(2, 1)
    Fichier = "C:\dossier\monFichier.txt"
    
    x = FreeFile
    'Transfère des infos du fichier txt vers une collection.
    Open Fichier For Input As #x
        While Not EOF(x)
            Line Input #x, strLigne
            objCol.Add strLigne
        Wend
    Close #x
    
    'Suppression des lignes spécifiées dans la collection.
    For i = 1 To UBound(Tableau)
        If objCol.Count > Tableau(i) Then _
            objCol.Remove Tableau(i)
    Next i
    
    'Transfère la collection vers le fichier txt.
    Open Fichier For Output As #x
        For i = 1 To objCol.Count
            Print #x, objCol(i)
        Next
    Close #x
End Sub


Bonne soirée
MichelXld
MichelXld est déconnecté   Réponse avec citation