VBA: retours à la ligne

Résolu/Fermé
honey2 Messages postés 6 Date d'inscription jeudi 7 mars 2013 Statut Membre Dernière intervention 22 juillet 2013 - Modifié par honey2 le 9/04/2013 à 15:20
honey2 Messages postés 6 Date d'inscription jeudi 7 mars 2013 Statut Membre Dernière intervention 22 juillet 2013 - 10 avril 2013 à 09:25
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

f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701
9 avril 2013 à 15:58
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
honey2 Messages postés 6 Date d'inscription jeudi 7 mars 2013 Statut Membre Dernière intervention 22 juillet 2013
10 avril 2013 à 09:25
Merci c'est magique, c'est magnifique :)
0