VBA: retours à la ligne

Résolu
honey2 Messages postés 7 Statut Membre -  
honey2 Messages postés 7 Statut Membre -
Bonjour,
Voici mon code qui consiste à afficher un fichier txt(Conf) :

Sub Bouton1()

' Bouton1_Cliquer Macro
'
Dim fs As Object, a As Object, s2 As String, i As Integer
Dim derlign As Long, lignFinal&

Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\test2.txt", True)
i = 1

While Not IsEmpty(Cells(9, i))

While Not IsEmpty(Cells(11, i))
'Chr(13) & Chr(10) POUR LE SAUT DE LIGNE
'chr(9) pour la tabulation

s2 = s2 & vlan & " " & Cells(9, i) & Chr(13) & Chr(10) & Chr(9)
s2 = s2 & "name" & " " & Cells(10, i) & " " & Chr(13) & Chr(10) & Chr(9)
s2 = s2 & "ip address" & " " & Cells(11, i) & " " & Cells(12, i) & Chr(13) & Chr(10) & Chr(9)
s2 = s2 & "tagged" & " " & Cells(13, i) & Chr(13) & Chr(10) & Chr(9)
s2 = s2 & "untagged" & " " & Cells(14, i) & Chr(13) & Chr(10) & Chr(9)
s2 = s2 & "qos" & " " & "priority" & " " & Cells(15, i) & Chr(13) & Chr(10) & Chr(9)

i = i + 1

Wend
Wend

a.WriteLine s2
a.Close

End Sub

''''''''''''''''

Mon problème est que ca affiche le premier vlan au début de la ligne et les autres en tabulation:

Je voudrai que à chaque fois il y a vlan que ça reviens à la ligne comme le 1er.

Des idées ???

2 réponses

  1. f894009 Messages postés 17417 Date d'inscription   Statut Membre Dernière intervention   1 717
     
    Bonjour,

    Si j'ai bien compris votre demande,

    Sub Bouton1()
    
        ' Bouton1_Cliquer Macro
    '
        Dim fs As Object, a As Object, s2 As String, i As Integer
        Dim derlign As Long, lignFinal&
    
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set a = fs.CreateTextFile("c:\test2.txt", True)
        i = 1
    
        While Not IsEmpty(Cells(9, i))
            While Not IsEmpty(Cells(11, i))
                'Chr(13) & Chr(10) POUR LE SAUT DE LIGNE ou vbNewLine
                'chr(9) pour la tabulation ou vbTab
    
                s2 = s2 & vlan & " " & Cells(9, i) & vbNewLine & vbTab
                s2 = s2 & "name" & " " & Cells(10, i) & " " & vbNewLine & vbTab
                s2 = s2 & "ip address" & " " & Cells(11, i) & " " & Cells(12, i) & vbNewLine & vbTab
                s2 = s2 & "tagged" & " " & Cells(13, i) & vbNewLine & vbTab
                s2 = s2 & "untagged" & " " & Cells(14, i) & vbNewLine & vbTab
                s2 = s2 & "qos" & " " & "priority" & " " & Cells(15, i) & vbNewLine
                i = i + 1
            Wend
        Wend
        a.WriteLine s2
        a.Close
    
    End Sub
    


    Bonne suite
    1
  2. honey2 Messages postés 7 Statut Membre
     
    Merci c'est magique, c'est magnifique :)
    0