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

Macros et VBA Excel Discussion :

Copier un fichier excel en entier


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2017
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Bâtiment

    Informations forums :
    Inscription : Septembre 2017
    Messages : 36
    Par défaut Copier un fichier excel en entier
    Bonjour, j'ai une macro qui s'exécute bien à une condition près. Je veux copier un fichier excel en entier et non une feuille, pouvez-vous me dire comment faire s'il vous plaît ?

  2. #2
    Invité
    Invité(e)

  3. #3
    Expert éminent Avatar de Menhir
    Homme Profil pro
    Ingénieur
    Inscrit en
    Juin 2007
    Messages
    16 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 16 037
    Par défaut
    Citation Envoyé par naudju Voir le message
    j'ai une macro qui s'exécute bien à une condition près. Je veux copier un fichier excel en entier et non une feuille
    Il serait bien déjà que tu montres le code que tu as fais pour qu'on comprenne mieux la question.
    Parce que là, c'est franchement flou.

  4. #4
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2017
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Bâtiment

    Informations forums :
    Inscription : Septembre 2017
    Messages : 36
    Par défaut
    Citation Envoyé par Menhir Voir le message
    Il serait bien déjà que tu montres le code que tu as fais pour qu'on comprenne mieux la question.
    Parce que là, c'est franchement flou.
    oui tu as raison, voici le morceau de mon code où il est question de la sauvegarde

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    FS.ActiveSheet.Copy
        extension = ".xlsx"
        chemin = "F:\Alliaserv TPF\2eme macro copiecolle\"
        nomfichier = "Fiche de synhèse_" & Nom_affaire.Offset(i) & extension
    With ActiveWorkbook
        .SaveAs Filename:=chemin & nomfichier
        .Close
    End With
    la ça me copie juste la page active de mon fichier FS, mais j'aimerai copier tout FS (avec toutes les feuilles qu'il a et non juste la feuille active

  5. #5
    Expert confirmé
    Avatar de MarcelG
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2009
    Messages
    3 449
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2009
    Messages : 3 449
    Billets dans le blog
    7
    Par défaut
    Salut,

    Normal.
    Tu copies une feuille sans autre argument.
    La conséquence en est la création d'un nouveau classeur ne comportant que cette feuille.

  6. #6
    Expert éminent Avatar de Menhir
    Homme Profil pro
    Ingénieur
    Inscrit en
    Juin 2007
    Messages
    16 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 16 037
    Par défaut
    En fait, tu en fais trop.
    Le Copy ne pourrait être utile que si tu ne voulais copier qu'une partie des feuilles de ton fichier.
    Puisque tu veux tout copier, autant le faire direct.
    Et si tu veux garder ton fichier d'origine actif avec son nom, tu peux utiliser SaveCopyAs.
    Et du coup, le Close et le With aussi deviennent inutiles.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    extension = ".xlsx"
    chemin = "F:\Alliaserv TPF\2eme macro copiecolle\"
    nomfichier = "Fiche de synhèse_" & Nom_affaire.Offset(i) & extension
    FS.SaveCopyAs Filename:=chemin & nomfichier
    Je pense que la variable extension aussi est inutile. Excel mettra sans doute la bonne extension de lui-même.

  7. #7
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2017
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Bâtiment

    Informations forums :
    Inscription : Septembre 2017
    Messages : 36
    Par défaut
    Super ! Merci à vous cela marche parfaitement !!

    Petit plus, je voudrais juste savoir s'il y avait des outils pour réduire le temps d'exécution de mon programme ?

    Mon programme copie un fichier vide en plus je ne sais pas pour quelle raison

    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
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    '
    ' test_copie Macroi
     
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
     
    Dim Wk, FST, FS As Workbook
    Dim derniere_ligne_FST As Integer
    Dim i As Integer 'nombre de ligne rempli dans le tableau
    Dim j As Integer 'permet de détacter la dernière cellule pleine du tableau
    Dim dernier_ligne_tableau_FST As Integer
     Dim Numero_contrat As Range
     Dim Nom_affaire As Range
     Dim Nom_client As Range
     Dim Responsable As Range
     Dim Commercial As Range
     Dim mode As Range 'c'est le type dans la fiche de synthèse V2
     Dim chef_secteur As Range
     Dim Technicien As Range
     Dim adresse_affaire1 As Range 'adresse
     Dim adresse_affaire2 As Range 'code postal
     Dim adresse_affaire3 As Range 'ville
     Dim date_debut As Range
     Dim duree As Range
     Dim date_fin As Range
     Dim tacite_reconductible As Range
     Dim acces As Range
     Dim nom_contact1 As Range
     Dim nom_contact2 As Range
     Dim fonction_contact1 As Range
     Dim fonction_contact2 As Range
     Dim tel_contact1 As Range
     Dim tel_contact2 As Range
     Dim fax_contact1 As Range
     Dim fax_contact2 As Range
     Dim portable_contact1 As Range
     Dim portable_contact2 As Range
     Dim mail_contact1 As Range
     Dim mail_contact2 As Range
     Dim montant_annuel_P1 As Range
     Dim montant_annuel_P2 As Range
     Dim montant_annuel_P3 As Range
     Dim P1 As Range
     Dim P2 As Range
     Dim P3 As Range
     Dim A_interessement As Range
     Dim Disconnecteur As Range
     Dim Legionnelle As Range
     Dim Physico_chimique As Range
     Dim Adoucisseur As Range
     Dim Filtre_Courroie As Range
     Dim Traitement_eau As Range
     Dim Fluide_frigorigene As Range
     Dim Piece_inferieur_a As Range
     Dim Installation1 As Range
     Dim Installation2 As Range
     Dim Installation3 As Range
     Dim Combustible1 As Range
     Dim Combustible2 As Range
     Dim Combustible3 As Range
     Dim NB_Heure As Range
     Dim delai_intervention As Range
     Dim periodicite_visites As Range
     Dim sous_traitance1 As Range
     Dim sous_traitance2 As Range
    Dim extension As String
    Dim chemin As String
    Dim nomfichier As String
     
     
    'attribution et ouverture des différents classeurs
    Set Wk = ThisWorkbook
        fiche_de_synthèse_tbl = Wk.Sheets(1).Range("E10")
        fiche_de_synthèse_feuille = Wk.Sheets(1).Range("E11")
     
    Set FST = Workbooks.Open(fiche_de_synthèse_tbl)
    Set FS = Workbooks.Open(fiche_de_synthèse_feuille)
     
     
     
    'recherche des cellules dans FST
    Set Numero_contrat = FST.Sheets("fiche de synthèse").Cells.Find(what:="CODE_SITE")
    Set Nom_affaire = FST.Sheets("fiche de synthèse").Cells.Find(what:="Denomination")
    Set Nom_client = FST.Sheets("fiche de synthèse").Cells.Find(what:="NOM_C")
    Set Responsable = FST.Sheets("fiche de synthèse").Cells.Find(what:="Responsable")
    Set Commercial = FST.Sheets("fiche de synthèse").Cells.Find(what:="Commercial")
    Set mode = FST.Sheets("fiche de synthèse").Cells.Find(what:="Type_S")
    Set chef_secteur = FST.Sheets("fiche de synthèse").Cells.Find(what:="Chef_de_secteur")
    Set Technicien = FST.Sheets("fiche de synthèse").Cells.Find(what:="Technicien")
    Set adresse_affaire1 = FST.Sheets("fiche de synthèse").Cells.Find(what:="ADR1_S")
    Set adresse_affaire2 = FST.Sheets("fiche de synthèse").Cells.Find(what:="CP_S")
    Set adresse_affaire3 = FST.Sheets("fiche de synthèse").Cells.Find(what:="VILLE_S")
    Set date_debut = FST.Sheets("fiche de synthèse").Cells.Find(what:="DATE_DEBUT")
    Set duree = FST.Sheets("fiche de synthèse").Cells.Find(what:="Duree_en_mois")
    Set date_fin = FST.Sheets("fiche de synthèse").Cells.Find(what:="Date_de_fin")
    Set tacite_reconductible = FST.Sheets("fiche de synthèse").Cells.Find(what:="RECONDUCTION")
    Set acces = FST.Sheets("fiche de synthèse").Cells.Find(what:="COMMENTAIRE")
    Set nom_contact1 = FST.Sheets("fiche de synthèse").Cells.Find(what:="NOM2")
    Set nom_contact2 = FST.Sheets("fiche de synthèse").Cells.Find(what:="NOM3")
    Set fonction_contact1 = FST.Sheets("fiche de synthèse").Cells.Find(what:="fonction_1")
    Set fonction_contact2 = FST.Sheets("fiche de synthèse").Cells.Find(what:="fonction_2")
    Set tel_contact1 = FST.Sheets("fiche de synthèse").Cells.Find(what:="FIXE1")
    Set tel_contact2 = FST.Sheets("fiche de synthèse").Cells.Find(what:="FIXE2")
    Set fax_contact1 = FST.Sheets("fiche de synthèse").Cells.Find(what:="FAX1")
    Set fax_contact2 = FST.Sheets("fiche de synthèse").Cells.Find(what:="FAX2")
    Set portable_contact1 = FST.Sheets("fiche de synthèse").Cells.Find(what:="TEL1")
    Set portable_contact2 = FST.Sheets("fiche de synthèse").Cells.Find(what:="TEL2")
    Set mail_contact1 = FST.Sheets("fiche de synthèse").Cells.Find(what:="MAIL2")
    Set mail_contact2 = FST.Sheets("fiche de synthèse").Cells.Find(what:="MAIL3")
    Set montant_annuel_P1 = FST.Sheets("fiche de synthèse").Cells.Find(what:="Montant_Annuel_P1_HT")
    Set montant_annuel_P2 = FST.Sheets("fiche de synthèse").Cells.Find(what:="Montant_Annuel_P2_HT")
    Set montant_annuel_P3 = FST.Sheets("fiche de synthèse").Cells.Find(what:="Montant_Annuel_P3_HT")
    Set P1 = FST.Sheets("fiche de synthèse").Cells.Find(what:="P1")
    Set P2 = FST.Sheets("fiche de synthèse").Cells.Find(what:="P2")
    Set P3 = FST.Sheets("fiche de synthèse").Cells.Find(what:="P3")
    Set A_interessement = FST.Sheets("fiche de synthèse").Cells.Find(what:="A_interessement")
    Set Disconnecteur = FST.Sheets("fiche de synthèse").Cells.Find(what:="Disconnecteur")
    Set Legionnelle = FST.Sheets("fiche de synthèse").Cells.Find(what:="Legionnelle")
    Set Physico_chimique = FST.Sheets("fiche de synthèse").Cells.Find(what:="Physico-chimique")
    Set Adoucisseur = FST.Sheets("fiche de synthèse").Cells.Find(what:="Adoucisseur")
    Set Filtre_Courroie = FST.Sheets("fiche de synthèse").Cells.Find(what:="Filtre/Courroie")
    Set Traitement_eau = FST.Sheets("fiche de synthèse").Cells.Find(what:="Traitement_eau")
    Set Fluide_frigorigene = FST.Sheets("fiche de synthèse").Cells.Find(what:="Fluide_frigorigene")
    Set Piece_inferieur_a = FST.Sheets("fiche de synthèse").Cells.Find(what:="Piece_inferieur_a")
    Set Installation1 = FST.Sheets("fiche de synthèse").Cells.Find(what:="Installation1")
    Set Installation2 = FST.Sheets("fiche de synthèse").Cells.Find(what:="Installation2")
    Set Installation3 = FST.Sheets("fiche de synthèse").Cells.Find(what:="Installation3")
    Set Combustible1 = FST.Sheets("fiche de synthèse").Cells.Find(what:="Combustible1")
    Set Combustible2 = FST.Sheets("fiche de synthèse").Cells.Find(what:="Combustible2")
    Set Combustible3 = FST.Sheets("fiche de synthèse").Cells.Find(what:="Combustible3")
    Set NB_Heure = FST.Sheets("fiche de synthèse").Cells.Find(what:="PREVISION_TEMPS")
    Set delai_intervention = FST.Sheets("fiche de synthèse").Cells.Find(what:="Delai_intervention")
    Set periodicite_visites = FST.Sheets("fiche de synthèse").Cells.Find(what:="Periodicite_visites")
    Set sous_traitance1 = FST.Sheets("fiche de synthèse").Cells.Find(what:="sous_traitance1")
    Set sous_traitance2 = FST.Sheets("fiche de synthèse").Cells.Find(what:="sous_traitance2")
     
    'copie et collage des cellules cherchées
    j = 1
        While FST.Sheets("Fiche de synthèse").Cells(j, 2) <> ""
            j = j + 1
            Wend
            dernier_ligne_tableau_FST = j - 1
     
        For i = 1 To dernier_ligne_tableau_FST
     
    If Not Numero_contrat Is Nothing Then Numero_contrat.Offset(i).Copy FS.Sheets("ADM").Range("H2").MergeArea
    If Not Nom_affaire Is Nothing Then Nom_affaire.Offset(i).Copy FS.Sheets("ADM").Range("U1").MergeArea
    If Not Nom_client Is Nothing Then Nom_client.Offset(i).Copy FS.Sheets("ADM").Range("AE1").MergeArea
    If Not Responsable Is Nothing Then Responsable.Offset(i).Copy FS.Sheets("ADM").Range("I3").MergeArea
    If Not Commercial Is Nothing Then Commercial.Offset(i).Copy FS.Sheets("ADM").Range("V2").MergeArea
    If Not mode Is Nothing Then mode.Offset(i).Copy FS.Sheets("ADM").Range("AD2").MergeArea
    If Not chef_secteur Is Nothing Then chef_secteur.Offset(i).Copy FS.Sheets("ADM").Range("W3").MergeArea
    If Not Technicien Is Nothing Then Technicien.Offset(i).Copy FS.Sheets("ADM").Range("AF3").MergeArea
    If Not adresse_affaire1 Is Nothing Then adresse_affaire1.Offset(i).Copy FS.Sheets("ADM").Range("A6").MergeArea
    If Not adresse_affaire2 Is Nothing Then adresse_affaire2.Offset(i).Copy FS.Sheets("ADM").Range("A7").MergeArea
    If Not adresse_affaire3 Is Nothing Then adresse_affaire3.Offset(i).Copy FS.Sheets("ADM").Range("A8").MergeArea
    If Not date_debut Is Nothing Then date_debut.Offset(i).Copy FS.Sheets("ADM").Range("P7").MergeArea
    If Not duree Is Nothing Then duree.Offset(i).Copy FS.Sheets("ADM").Range("U7").MergeArea
    If Not date_fin Is Nothing Then date_fin.Offset(i).Copy FS.Sheets("ADM").Range("AC7").MergeArea
    If Not tacite_reconductible Is Nothing Then tacite_reconductible.Offset(i).Copy
        FS.Sheets("ADM").Range("AH7").PasteSpecial Paste:=xlPasteValues
    If Not acces Is Nothing Then acces.Offset(i).Copy FS.Sheets("ADM").Range("C10").MergeArea
    If Not nom_contact1 Is Nothing Then nom_contact1.Offset(i).Copy FS.Sheets("ADM").Range("C13").MergeArea
    If Not nom_contact2 Is Nothing Then nom_contact2.Offset(i).Copy FS.Sheets("ADM").Range("C18").MergeArea
    If Not fonction_contact1 Is Nothing Then fonction_contact1.Offset(i).Copy FS.Sheets("ADM").Range("D14").MergeArea
    If Not fonction_contact2 Is Nothing Then fonction_contact2.Offset(i).Copy FS.Sheets("ADM").Range("C19").MergeArea
    If Not tel_contact1 Is Nothing Then tel_contact1.Offset(i).Copy FS.Sheets("ADM").Range("B15").MergeArea
    If Not tel_contact2 Is Nothing Then tel_contact2.Offset(i).Copy FS.Sheets("ADM").Range("B20").MergeArea
    If Not fax_contact1 Is Nothing Then fax_contact1.Offset(i).Copy FS.Sheets("ADM").Range("G15").MergeArea
    If Not fax_contact1 Is Nothing Then fax_contact1.Offset(i).Copy FS.Sheets("ADM").Range("G20").MergeArea
    If Not portable_contact1 Is Nothing Then portable_contact1.Offset(i).Copy FS.Sheets("ADM").Range("B16").MergeArea
    If Not portable_contact2 Is Nothing Then portable_contact2.Offset(i).Copy FS.Sheets("ADM").Range("B21").MergeArea
    If Not mail_contact1 Is Nothing Then mail_contact1.Offset(i).Copy FS.Sheets("ADM").Range("C17").MergeArea
    If Not mail_contact2 Is Nothing Then mail_contact2.Offset(i).Copy FS.Sheets("ADM").Range("C22").MergeArea
    If Not montant_annuel_P1 Is Nothing Then montant_annuel_P1.Offset(i).Copy FS.Sheets("ADM").Range("G24").MergeArea
    If Not montant_annuel_P2 Is Nothing Then montant_annuel_P2.Offset(i).Copy FS.Sheets("ADM").Range("G25").MergeArea
    If Not montant_annuel_P3 Is Nothing Then montant_annuel_P3.Offset(i).Copy FS.Sheets("ADM").Range("G26").MergeArea
    If Not P1 Is Nothing Then P1.Offset(i).Copy
        FS.Sheets("ADM").Range("M11").PasteSpecial Paste:=xlPasteValues
    If Not P2 Is Nothing Then P2.Offset(i).Copy
        FS.Sheets("ADM").Range("P11").PasteSpecial Paste:=xlPasteValues
    If Not P3 Is Nothing Then P3.Offset(i).Copy
        FS.Sheets("ADM").Range("T11").PasteSpecial Paste:=xlPasteValues
    If Not A_interessement Is Nothing Then A_interessement.Offset(i).Copy
        FS.Sheets("ADM").Range("W11").PasteSpecial Paste:=xlPasteValues
    If Not Disconnecteur Is Nothing Then Disconnecteur.Offset(i).Copy
        FS.Sheets("ADM").Range("S19").PasteSpecial Paste:=xlPasteValues
    If Not Legionnelle Is Nothing Then Legionnelle.Offset(i).Copy
        FS.Sheets("ADM").Range("S20").PasteSpecial Paste:=xlPasteValues
    If Not Physico_chimique Is Nothing Then Physico_chimique.Offset(i).Copy
        FS.Sheets("ADM").Range("S21").PasteSpecial Paste:=xlPasteValues
    If Not Adoucisseur Is Nothing Then Adoucisseur.Offset(i).Copy
        FS.Sheets("ADM").Range("S22").PasteSpecial Paste:=xlPasteValues
    If Not Filtre_Courroie Is Nothing Then Filtre_Courroie.Offset(i).Copy
        FS.Sheets("ADM").Range("AB19").PasteSpecial Paste:=xlPasteValues
    If Not Traitement_eau Is Nothing Then Traitement_eau.Offset(i).Copy
        FS.Sheets("ADM").Range("AB20").PasteSpecial Paste:=xlPasteValues
    If Not Fluide_frigorigene Is Nothing Then Fluide_frigorigene.Offset(i).Copy
        FS.Sheets("ADM").Range("AB21").PasteSpecial Paste:=xlPasteValues
    If Not Piece_inferieur_a Is Nothing Then Piece_inferieur_a.Offset(i).Copy FS.Sheets("ADM").Range("Z22").MergeArea
    If Not Installation1 Is Nothing Then Installation1.Offset(i).Copy FS.Sheets("ADM").Range("P15").MergeArea
    If Not Installation2 Is Nothing Then Installation2.Offset(i).Copy FS.Sheets("ADM").Range("P16").MergeArea
    If Not Installation3 Is Nothing Then Installation3.Offset(i).Copy FS.Sheets("ADM").Range("P17").MergeArea
    If Not Combustible1 Is Nothing Then Combustible1.Offset(i).Copy FS.Sheets("ADM").Range("Y15").MergeArea
    If Not Combustible2 Is Nothing Then Combustible2.Offset(i).Copy FS.Sheets("ADM").Range("Y16").MergeArea
    If Not Combustible3 Is Nothing Then Combustible3.Offset(i).Copy FS.Sheets("ADM").Range("Y17").MergeArea
    If Not NB_Heure Is Nothing Then NB_Heure.Offset(i).Copy FS.Sheets("ADM").Range("AK18").MergeArea
    If Not delai_intervention Is Nothing Then delai_intervention.Offset(i).Copy FS.Sheets("ADM").Range("AK19").MergeArea
    If Not periodicite_visites Is Nothing Then periodicite_visites.Offset(i).Copy FS.Sheets("ADM").Range("AJ20").MergeArea
    If Not sous_traitance1 Is Nothing Then sous_traitance1.Offset(i).Copy FS.Sheets("ADM").Range("AH21").MergeArea
    If Not sous_traitance2 Is Nothing Then sous_traitance2.Offset(i).Copy FS.Sheets("ADM").Range("AH22").MergeArea
     
     
    'ici on enregistre et on ferme toutes les fiches de synthèse
        extension = ".xlsx"
        chemin = "F:\Alliaserv TPF\2eme macro copiecolle\"
        nomfichier = "Fiche de synhèse_" & Nom_affaire.Offset(i) & extension
    FS.SaveCopyAs Filename:=chemin & nomfichier
     
     
        Next
    FS.Close
    FST.Close
     
     
    Application.ScreenUpdating = True
     
    End Sub

    là je copie toutes les cellules mêmes quand il n'y a rien a l'interieur, je pense que je pourrais gagner du temps en copiant que s'il y a une cellule remplie. Mais j'aimerai ne pas tout changer... vous avez une solution ?

  8. #8
    Invité
    Invité(e)
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     chemin = Replace(fs.FullName, fs.Name, "Fiche de synhèse_" & Split(fs.Name & ".xlsx", ".")(0) & ".") & Split(fs.Name & ".xlsx", ".")(1)
     fs.SaveCopyAs chemin

  9. #9
    Expert confirmé
    Avatar de MarcelG
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2009
    Messages
    3 449
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2009
    Messages : 3 449
    Billets dans le blog
    7
    Par défaut
    Salut,

    En complément du post de dysorthographie,
    Si copie de plusieurs feuilles sans les modules du classeur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Option Explicit
     
    Public Sub escop()
    ThisWorkbook.Worksheets(Array("lala", "tutu")).Copy
    ActiveWorkbook.SaveAs Filename:="leclasseur.xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    End Sub
    A adapter bien sûr.

  10. #10
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    n'oublis pas qu'un informaticien c'est un fainéant comme tous les utilisateurs des macro qu'il développe!
    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
    With FST.Sheets("fiche de synthèse").Cells
        Set Numero_contrat = .Find(what:="CODE_SITE")
        Set Nom_affaire = .Find(what:="Denomination")
        Set Nom_client = .Find(what:="NOM_C")
        Set Responsable = .Find(what:="Responsable")
        Set Commercial = .Find(what:="Commercial")
        Set Mode = .Find(what:="Type_S")
        Set chef_secteur = .Find(what:="Chef_de_secteur")
        Set Technicien = .Find(what:="Technicien")
        Set adresse_affaire1 = .Find(what:="ADR1_S")
        Set adresse_affaire2 = .Find(what:="CP_S")
        Set adresse_affaire3 = .Find(what:="VILLE_S")
        Set date_debut = .Find(what:="DATE_DEBUT")
        Set duree = .Find(what:="Duree_en_mois")
        Set date_fin = .Find(what:="Date_de_fin")
        Set tacite_reconductible = .Find(what:="RECONDUCTION")
        Set acces = .Find(what:="COMMENTAIRE")
        Set nom_contact1 = .Find(what:="NOM2")
        Set nom_contact2 = .Find(what:="NOM3")
        Set fonction_contact1 = .Find(what:="fonction_1")
        Set fonction_contact2 = .Find(what:="fonction_2")
        Set tel_contact1 = .Find(what:="FIXE1")
        Set tel_contact2 = .Find(what:="FIXE2")
        Set fax_contact1 = .Find(what:="FAX1")
        Set fax_contact2 = .Find(what:="FAX2")
        Set portable_contact1 = .Find(what:="TEL1")
        Set portable_contact2 = .Find(what:="TEL2")
        Set mail_contact1 = .Find(what:="MAIL2")
        Set mail_contact2 = .Find(what:="MAIL3")
        Set montant_annuel_P1 = .Find(what:="Montant_Annuel_P1_HT")
        Set montant_annuel_P2 = .Find(what:="Montant_Annuel_P2_HT")
        Set montant_annuel_P3 = .Find(what:="Montant_Annuel_P3_HT")
        Set P1 = .Find(what:="P1")
        Set P2 = .Find(what:="P2")
        Set P3 = .Find(what:="P3")
        Set A_interessement = .Find(what:="A_interessement")
        Set Disconnecteur = .Find(what:="Disconnecteur")
        Set Legionnelle = .Find(what:="Legionnelle")
        Set Physico_chimique = .Find(what:="Physico-chimique")
        Set Adoucisseur = .Find(what:="Adoucisseur")
        Set Filtre_Courroie = .Find(what:="Filtre/Courroie")
        Set Traitement_eau = .Find(what:="Traitement_eau")
        Set Fluide_frigorigene = .Find(what:="Fluide_frigorigene")
        Set Piece_inferieur_a = .Find(what:="Piece_inferieur_a")
        Set Installation1 = .Find(what:="Installation1")
        Set Installation2 = .Find(what:="Installation2")
        Set Installation3 = .Find(what:="Installation3")
        Set Combustible1 = .Find(what:="Combustible1")
        Set Combustible2 = .Find(what:="Combustible2")
        Set Combustible3 = .Find(what:="Combustible3")
        Set NB_Heure = .Find(what:="PREVISION_TEMPS")
        Set delai_intervention = .Find(what:="Delai_intervention")
        Set periodicite_visites = .Find(what:="Periodicite_visites")
        Set sous_traitance1 = .Find(what:="sous_traitance1")
        Set sous_traitance2 = .Find(what:="sous_traitance2")
    End With

  11. #11
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2017
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Bâtiment

    Informations forums :
    Inscription : Septembre 2017
    Messages : 36
    Par défaut
    merci dysorthographie, je ne pensais pas que le fait de juste faire une boucle with me ferais gagné du temps ! Ca me fait gagner 1/4 du temps

    encore merci a vous

Discussions similaires

  1. [XL-2003] Copier 3 fichiers excel dans 1.
    Par visto94 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 06/09/2010, 13h26
  2. Réponses: 2
    Dernier message: 20/08/2010, 16h06
  3. macro pour copier un fichier excel dans un dossier
    Par mery13 dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 20/03/2009, 13h36
  4. Copier un fichier excel dans un power point
    Par jhpotter dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 21/05/2008, 10h11
  5. [POI]copier/coller fichier Excel
    Par yas2006 dans le forum Documents
    Réponses: 3
    Dernier message: 23/03/2006, 20h16

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