VBA : TRAITEMENT D’UN CLASSEUR EXCEL POUR CONVERSION EN FICHIER TEXTE

/// Option Explicit Dim ligne(0, 5) As Variant Dim l, c As Long Dim i As Long Dim Compte As String Dim Nom As String Dim reference As String Dim datedoc As String Dim Echeance As String Dim debit, credit As Double Dim Libelle As String Dim Filesys, FichierSortie As Object Dim NomFichierSauvegarde As String Dim Enregistrement As String Dim tabu As String Sub traitement() tabu = Chr(9) NomFichierSauvegarde = « G:\ANCLIENTS.TXT » Call fichier Worksheets(« Grand-livre des tiers »).Activate Range(« A1 »).Select While ActiveCell.Value <> «  » l = ActiveCell.Row c = ActiveCell.Column ‘*********** i = 0 While i < 6 ligne(0, i) = Cells(l, c + i).Value i = i + 1 Wend '*********** If ligne(0, 2) <> «  » Then Compte = « 411 » + Left(ligne(0, 0) + « 0000000000000 », 12) Nom = ligne(0, 2) Else reference = ligne(0, 1) datedoc = ligne(0, 0) Echeance = ligne(0, 3) debit = ligne(0, 4) credit = ligne(0, 5) If credit = 0 Then Libelle = « Facture  » & reference &  »  » &  » du  » & datedoc Else Libelle = « Avoir  » & reference &  »  » &  » du  » & datedoc End If ‘construction de l’enregistrement Enregistrement = « REP » + tabu + « 01/01/2016 » + tabu + reference + tabu + Compte + tabu + Libelle + tabu + CStr(debit) + tabu + CStr(credit) + tabu + Echeance ‘ + tabu + debit + tabu + credit ‘enregistrement FichierSortie.Writeline Enregistrement End If Cells(l + 1, c).Select Wend ‘fin de l’enregistrement ‘fermeture du fichier FichierSortie.Close Set FichierSortie = Nothing Call MsgBox(« Le fichier a été correctement généré,  » _ & vbCrLf & « vous pouvez maintenant quitter le programme et déposer le fichier. » _ , vbInformation, « TRAITEMENT TERMINE ») End Sub Sub fichier() ‘Ouverture du fichier ‘================================================ Set Filesys = CreateObject(« Scripting.FileSystemObject ») Set FichierSortie = Filesys.CreateTextFile(NomFichierSauvegarde) End Sub ///

Laisser un commentaire