IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Contribuez Discussion :

Fusion de fichiers Excel CSV


Sujet :

Contribuez

  1. #1
    Expert éminent sénior
    Avatar de kiki29
    Homme Profil pro
    ex Observeur CGG / Analyste prog.
    Inscrit en
    Juin 2006
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : ex Observeur CGG / Analyste prog.

    Informations forums :
    Inscription : Juin 2006
    Messages : 6 132
    Points : 11 274
    Points
    11 274
    Par défaut Fusion de fichiers Excel CSV
    Cet utilitaire permet de faire l'inverse du Découpage d'un fichier Excel CSV

    Téléchargeable ici : Fusion de fichiers Excel CSV

    Extrait :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    Sub FusionFichiers()
    Dim i As Long, iEntete As Long, bFirst As Boolean, bEntete As Boolean
    Dim iLast As Long, iLastRow As Long, iLastCol As Long, bVide As Boolean, FSO As Object
    Dim WkbFusion As Workbook, WkbDecoupage As Workbook, bDoublons As Boolean
    Dim sDossier As String, sNomDossier As String, sDossierDecoupage As String, sPre As String, sNouveauNom As String
     
        QueryPerformanceCounter Dep
     
        Application.StatusBar = ""
        DecompteA
     
        sDossierDecoupage = ShParam.Range("A1")
     
        bVide = ShParam.CheckBoxes("chkVider").Value = 1
        bDoublons = ShParam.CheckBoxes("chkDoublons").Value = 1
        If bVide Then
            ShParam.CheckBoxes("chkDoublons").Value = 0
            bDoublons = False
        End If
        If Cpt = 0 Then
            MsgBox "Taper dans la colonne A un x ou X en vis à vis" & vbCrLf & _
                   "des fichiers à Fusionner de la colonne B", vbInformation + vbOKOnly, "x ou X"
            Exit Sub
        End If
     
        sNomDossier = ShParam.Range("D7")
        sPre = ShParam.Range("D8")
        iEntete = ShParam.Range("D9")
        bEntete = ShParam.CheckBoxes("chkEntete").Value = 1
     
        sDossier = ThisWorkbook.Path & "\" & sNomDossier
        If bVide Then
            Set FSO = CreateObject("Scripting.FileSystemObject")
            If FSO.FolderExists(sDossier) Then FSO.DeleteFolder sDossier, True
            Set FSO = Nothing
        End If
     
        CreationDossier sDossier
     
        Application.ScreenUpdating = False
        bFirst = True
        iLast = ShParam.Range("B" & Rows.Count).End(xlUp).Row
     
        If bFirst Then
            Set WkbFusion = Workbooks.Add
        End If
     
        For i = RDepart To iLast
            If UCase$(ShParam.Range("A" & i)) = "X" Then
                Set WkbDecoupage = Workbooks.Open(Filename:=sDossierDecoupage & "\" & ShParam.Range("B" & i), ReadOnly:=True, Local:=True)
                With WkbDecoupage.Worksheets(1)
                    iLastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
                    iLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
                    If bEntete Then
                        .Range("A1:A" & iEntete).Resize(, iLastCol).Copy WkbFusion.Worksheets(1).Range("A1")
                        .Range(.Cells(iEntete + 1, "A"), .Cells(iLastRow, iLastCol)).Copy WkbFusion.Worksheets(1).Cells(Rows.Count, "A").End(xlUp).Offset(1)
                    Else
                        .Range(.Cells(iEntete + 1, "A"), .Cells(iLastRow, iLastCol)).Copy WkbFusion.Worksheets(1).Cells(Rows.Count, "A").End(xlUp)
                    End If
                    WkbDecoupage.Close SaveChanges:=False
                End With
                Set WkbDecoupage = Nothing
                Application.StatusBar = i - RDepart + 1 & " / " & iLast - RDepart + 1
            End If
        Next i
     
        WkbFusion.Worksheets(1).Columns.AutoFit
        If bDoublons Then
            sNouveauNom = RenommerFichier(sDossier, sPre & ".xls")
        Else
            sNouveauNom = sDossier & "\" & sPre & ".xls"
        End If
     
        Application.DisplayAlerts = False
        If bEntete Then
            EnteteClasseurTempo iEntete, WkbFusion
        Else
            EnteteClasseurTempoNo WkbFusion
        End If
        WkbFusion.SaveAs sNouveauNom
        WkbFusion.Close
        Set WkbFusion = Nothing
     
        With Application
            .DisplayAlerts = True
            .ScreenUpdating = True
        End With
        With ShParam
            .Select
            .Range("B2").Select
        End With
     
        QueryPerformanceCounter Fin
        QueryPerformanceFrequency Freq
        Application.StatusBar = Application.StatusBar & " / Terminé : " & Format(((Fin - Dep) / Freq), "0.000 s")
    End Sub
    Images attachées Images attachées  

Discussions similaires

  1. fusion de fichiers excel en un seul fichier
    Par croset dans le forum Macros et VBA Excel
    Réponses: 41
    Dernier message: 15/11/2008, 21h56
  2. [MySQL] convertir un fichier excel(*.csv) en un (*.sql)
    Par rhani2010 dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 16/10/2006, 19h39
  3. sauvegarde d'un fichier excel csv sous le format xls
    Par blondelle dans le forum C++Builder
    Réponses: 5
    Dernier message: 01/08/2006, 11h30
  4. Import de fichier Excel (CSV) dans MySQL
    Par mathieu77186 dans le forum Outils
    Réponses: 2
    Dernier message: 27/03/2006, 23h23
  5. Réponses: 1
    Dernier message: 02/02/2006, 14h26

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo