Note: The other languages of the website are Google-translated. Back to English
Se connecter  \/ 
x
or
x
INSCRIPTION  \/ 
x

or

Comment enregistrer, exporter plusieurs / toutes les feuilles pour séparer des fichiers csv ou texte dans Excel?

Lorsque vous utilisez Excel, vous pouvez enregistrer manuellement une feuille de calcul en tant que fichier csv ou texte par la fonction Enregistrer sous. Cependant, comment pouvez-vous faire pour convertir plusieurs ou toutes les feuilles d'un classeur en fichier CSV ou texte séparé? Dans cet article, nous vous montrerons les méthodes d'enregistrement ou de conversion de plusieurs feuilles ou de toutes les feuilles en fichier CSV ou texte séparé.

Enregistrez, exportez ou convertissez toutes les feuilles en fichier csv ou texte avec le code VBA
Enregistrer, exporter ou convertir plusieurs / toutes les feuilles en fichier csv ou texte avec Kutools for Excel


Enregistrez, exportez ou convertissez toutes les feuilles en fichier csv ou texte avec le code VBA

Avec les codes VBA ci-dessous, vous pouvez enregistrer toutes les feuilles de calcul d'un classeur dans des fichiers CSV ou texte séparés. Veuillez faire comme suit.

Exporter ou convertir toutes les feuilles en fichiers csv

1. presse autre + F11 touches simultanément pour ouvrir le Application Microsoft Visual Basic fenêtre.

2. dans le Application Microsoft Visual Basic fenêtre, cliquez sur insérer > Module. Ensuite, copiez et collez le code suivant dans le Module fenêtre.

Code VBA: exportez toutes les feuilles vers des fichiers csv séparés

Sub ExportSheetsToCSV()
	Dim xWs As Worksheet
	Dim xcsvFile As String
	For Each xWs In Application.ActiveWorkbook.Worksheets
		xWs.Copy
		xcsvFile = CurDir & "\" & xWs.Name & ".csv"
		Application.ActiveWorkbook.SaveAs Filename: = xcsvFile, _
		FileFormat: = xlCSV, CreateBackup: = False
		Application.ActiveWorkbook.Saved = True
		Application.ActiveWorkbook.Close
	Next
End Sub

3. appuie sur le F5 clé pour exécuter le code. Vous verrez que tous les fichiers csv exportés se trouvent sur le Documents dossier. Voir la capture d'écran:

Exporter ou convertir toutes les feuilles en fichiers texte

Le code suivant peut vous aider à exporter ou à convertir toutes les feuilles du classeur en fichiers texte séparés.

Code VBA: exportez toutes les feuilles vers des fichiers texte séparés

Sub ExportSheetsToText()
	Dim xWs As Worksheet
	Dim xTextFile As String
	For Each xWs In Application.ActiveWorkbook.Worksheets
		xWs.Copy
		xTextFile = CurDir & "\" & xWs.Name & ".txt"
		Application.ActiveWorkbook.SaveAs Filename: = xTextFile, FileFormat: = xlText
		Application.ActiveWorkbook.Saved = True
		Application.ActiveWorkbook.Close
	Next
End Sub

Les fichiers texte exportés se trouvent également sur le Documents dossier. Voir la capture d'écran:


Enregistrer, exporter ou convertir plusieurs / toutes les feuilles en fichier csv ou texte avec Kutools for Excel

YVous pouvez rapidement exporter ou convertir plusieurs feuilles ou toutes les feuilles en fichiers CSV individuels, fichiers texte ou fichiers au format xls dans Excel avec le Classeur fractionné utilité de Kutools pour Excel.

Avant d'appliquer Kutools pour Excel, S'il vous plaît téléchargez et installez-le d'abord.

1. Cliquez Kutools Plus > Classeur > Classeur fractionné. Voir la capture d'écran:

2. dans le Classeur fractionné boite de dialogue:

  • 1). Si vous souhaitez convertir toutes les feuilles en fichiers csv ou texte, gardez simplement tous les noms de feuille cochés dans le Nom de la feuille de travail boîte; Si vous souhaitez simplement convertir plusieurs feuilles, continuez à les vérifier et décochez les autres feuilles que vous ne souhaitez pas convertir.
  • 2). dans le Options : section, vérifiez la Enregistrer en tant que type de puis sélectionnez Texte Unicode (*. Txt) or CSV (Macintosh) (*. Csv) dans la liste déroulante.
  • 3). Clique le Divisé .

3. dans le Parcourir pour le dossier boîte de dialogue, spécifiez un dossier pour enregistrer les fichiers exportés, puis cliquez sur le OK .

Désormais, toutes les feuilles ou feuilles spécifiées sont converties en fichiers CSV ou texte séparés et se trouvent dans le dossier comme vous l'avez spécifié ci-dessus.

  Si vous souhaitez bénéficier d'un essai gratuit (30 jours) de cet utilitaire, veuillez cliquer pour le télécharger, puis passez à appliquer l'opération selon les étapes ci-dessus.


Enregistrer, exporter ou convertir plusieurs / toutes les feuilles en fichier csv ou texte avec Kutools for Excel


Les meilleurs outils de productivité de bureau

Kutools for Excel résout la plupart de vos problèmes et augmente votre productivité de 80%

  • Réutilisation: Insérer rapidement formules complexes, graphiques et tout ce que vous avez utilisé auparavant; Crypter les cellules avec mot de passe; Créer une liste de diffusion et envoyer des e-mails ...
  • Barre Super Formula (modifiez facilement plusieurs lignes de texte et de formule); Disposition de lecture (lire et modifier facilement un grand nombre de cellules); Coller dans la plage filtrée...
  • Fusionner les cellules / lignes / colonnes sans perdre de données; Contenu des cellules divisées; Combiner des lignes / colonnes en double... Empêcher les cellules en double; Comparer les gammes...
  • Sélectionnez Dupliquer ou Unique Lignes; Sélectionnez les lignes vides (toutes les cellules sont vides); Super Find et Fuzzy Find dans de nombreux classeurs; Sélection aléatoire ...
  • Copie exacte Plusieurs cellules sans changer la référence de formule; Créer automatiquement des références à plusieurs feuilles; Insérer des puces, Cases à cocher et plus encore ...
  • Extrait du texte, Ajouter du texte, Supprimer par position, Supprimer l'espace; Créer et imprimer des sous-totaux de pagination; Conversion entre le contenu et les commentaires des cellules...
  • Super filtre (enregistrer et appliquer des schémas de filtrage à d'autres feuilles); Tri avancé par mois / semaine / jour, fréquence et plus; Filtre spécial par gras, italique ...
  • Combiner des classeurs et des feuilles de travail; Fusionner les tableaux en fonction des colonnes clés; Diviser les données en plusieurs feuilles; Conversion par lots xls, xlsx et PDF...
  • Plus de 300 fonctionnalités puissantes. Prend en charge Office / Excel 2007-2019 et 365. Prend en charge toutes les langues. Déploiement facile dans votre entreprise ou organisation. Essai gratuit de 30 jours. Garantie de remboursement de 60 jours.
onglet kte 201905

Office Tab apporte une interface à onglets à Office et simplifie considérablement votre travail

  • Activer l'édition et la lecture par onglets dans Word, Excel, PowerPoint, Publisher, Access, Visio et Project.
  • Ouvrez et créez plusieurs documents dans de nouveaux onglets de la même fenêtre, plutôt que dans de nouvelles fenêtres.
  • Augmente votre productivité de 50% et réduit des centaines de clics de souris chaque jour!
bas de cabine
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Tim · 26 days ago
    Thanks! I used this to save all the sheets of my .xlsx file into differents .xlsx

    Sub ExportSheetsToXLSX()
    Dim xWs As Worksheet
    Dim xcsvFile As String
    For Each xWs In Application.ActiveWorkbook.Worksheets
    xWs.Copy
    xlsxFile = CurDir & "\" & xWs.Name & ".xlsx"
    Application.ActiveWorkbook.SaveAs Filename:=xlsxFile, _
    FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    Application.ActiveWorkbook.Saved = True
    Application.ActiveWorkbook.Close
    Next
    End Sub
  • To post as a guest, your comment is unpublished.
    nathan · 2 years ago
    how would I change the code to have it save in a different file format such as an xlsx? or ASCII.
  • To post as a guest, your comment is unpublished.
    folivo1980 · 2 years ago
    So, this is great! BUT, what if I need to split a workbook into .csv but for PC, not MAC? If anyone has a way of doing it, please help me out. I will be very grateful.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi,
      The first VBA code in this post can do you a favor.
  • To post as a guest, your comment is unpublished.
    tarahjcollins@gmail.com · 2 years ago
    Is there a way to use this code to export only a certain range to a .csv file of each sheet in a book?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi,
      The VBA code in this article may do you a favor: https://www.extendoffice.com/documents/excel/2897-excel-export-range-to-csv.html
  • To post as a guest, your comment is unpublished.
    GrifoDeGrifis · 2 years ago
    Hello,
    thank you so much for a great macro, it works like a charm! But I have a question, what if I would like to save this macro (CSV version) on PERSONAL.xlsb as to make it available on any excel instance?

    When I try, CurDir takes the PERSONAL directory, instead of the active worksheet one...

    Thank you for any help!
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Mirko,
      Method in this article can do you a favor: https://trumpexcel.com/personal-macro-workbook/.
  • To post as a guest, your comment is unpublished.
    sharmaarvind951@gmail.com · 3 years ago
    If you just want to convert multiple sheets, keep checking them and going to uncheck other sheets you don’t want to convert
    sir for thuis step do you have macro
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Good day,
      Can't help with VBA code for this. Why not try the Split Workbook utility we provide in the post? It will save your time and you will love it.
  • To post as a guest, your comment is unpublished.
    sai · 3 years ago
    Superb solution.....Its saved my time.......Thank you
  • To post as a guest, your comment is unpublished.
    info@cameronstewart.com.au · 3 years ago
    Thanks - script very useful
  • To post as a guest, your comment is unpublished.
    Ken · 3 years ago
    A, I see now that the line "VBA code: Export all sheets to separated csv files" should not be copied into the code area. Perhaps that can be more explicit for newbies, and for people who follow instructions explicitly.
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Hi Ken,
      That's the description line of the code. The line "Sub ExportSheetsToCSV()" should be the first line of the code.
      I'm sorry for the inconvenience.
  • To post as a guest, your comment is unpublished.
    ritz · 3 years ago
    1) I have a workbook with multiple sheets in it.
    2) Those multiple sheets are having multiple columns.
    3) I have one column in each sheet which is concatenation of all the other columns.
    4) Now, I want to extract that concatenated column to a text file with the same name as sheet name.
    5) The way I want is I just press one button and it should look for all the tabs, extract that column (say concatenated column is AA) from each sheet, put that into a text file, name the text file same as sheet name and store in some directory on my desktop say H drive.
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Good Day,
      Sorry can’t help with this, you can post your question in our forum: https://www.extendoffice.com/forum.html to get more Excel supports from our professional.
  • To post as a guest, your comment is unpublished.
    vincent.abhishek@gmail.com · 3 years ago
    I need a macro to convert all the tabs in a excel file to different set of files.
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Good Day,
      Which files do you want to include in your "different set of files"?
  • To post as a guest, your comment is unpublished.
    tauseefamin@gmail.com · 4 years ago
    hi i need a macro which convert pipe "|" separated csv into xlsx asking folder name not a single file. i need it on urgent basis.


    Regards,
    • To post as a guest, your comment is unpublished.
      crystal · 4 years ago
      Sorry can't solve this problem
  • To post as a guest, your comment is unpublished.
    ashish · 4 years ago
    hello alex please could you display the code to save the files in csv format except the documents folder
  • To post as a guest, your comment is unpublished.
    Amit Chaudhary · 4 years ago
    Hi,
    Thanks for the code, I just have a small clarification. Currently when the CSV file generates it's delimited by comma ",". even though my system setting is for CSV the delimited should be pipe "|". Not sure why the CSV is generated with comma delimiter with the above code. Is there a way i can explicitly define the delimiter for the CSV file.

    Looking for your reply soonest.
    Thank.
    Regards,
    Amit
  • To post as a guest, your comment is unpublished.
    Tallrific · 4 years ago
    I'm writing to determine if your application can convert multiple xls sheets to one text file and how it would order the rows. I need to have an option to order the rows in order of appearance, one line at a time one sheet at a time. Sheet 1, row 1; sheet 2, row 1, sheet 3, row1, etc. I look forward to your feedback.
  • To post as a guest, your comment is unpublished.
    Mike · 5 years ago
    Thanks for the macros, they were just what I needed.
    However, using "CurDir" to build the output filepath is very dangerous as it is not necessarily the folder of the Excel file that was opened - it is generally the current folder in explorer so your files could end up getting written practically anywhere. You should use Application.ThisWorkbook.Path instead.
  • To post as a guest, your comment is unpublished.
    Nicolas · 5 years ago
    Hi, thank you for the code, is it possible to skip some sheets and only save a few?
    I've got no idea how I should start. Could you help me?

    Nicolas
  • To post as a guest, your comment is unpublished.
    Alex K123456789 · 5 years ago
    Is there any way to have the CSV files save to a folder other than the Documents folder?
    • To post as a guest, your comment is unpublished.
      Paul · 5 years ago
      [quote name="Alex K123456789"]Is there any way to have the CSV files save to a folder other than the Documents folder?[/quote]
      I haven't tested it, but I'm pretty the "\" in this line stands for the working directory: xcsvFile = CurDir & "\" & xWs.Name & ".csv"
      If you want to change the working directory, you'll have to add another command.
      If you want to save it to a folder within the working directory, say in a folder called new you just replace "\" with "\New\".
      Something along those lines.
      • To post as a guest, your comment is unpublished.
        ALEX K123456789 · 5 years ago
        Thank you very much Paul. I wound up figuring it out a little while back, but your solution is exactly what I did.
        • To post as a guest, your comment is unpublished.
          Dawn · 4 years ago
          Hi Alex,
          Could you show me the line of code you entered in place of the "\" please? I need to be able to save these .csv files to a location on our network rather than in my local WS library. We need to allow our Customer Service people to be able to access the file and rename the location each time it is used.
          I encounter bug problems with simply changing "\" to "\New\" (the VBA code does work as expected when copied straight from the info above). I am not code saavy, but I can follow directions fairly well, so any help is appreciated!
          • To post as a guest, your comment is unpublished.
            Alex K123456789 · 4 years ago
            [quote name="Dawn"]Hi Alex,
            Could you show me the line of code you entered in place of the "\" please? I need to be able to save these .csv files to a location on our network rather than in my local WS library. We need to allow our Customer Service people to be able to access the file and rename the location each time it is used.
            I encounter bug problems with simply changing "\" to "\New\" (the VBA code does work as expected when copied straight from the info above). I am not code saavy, but I can follow directions fairly well, so any help is appreciated![/quote]

            Hi Dawn, I wound up having to re-write portions and like Paul suggested, used a slightly different command. Below is the command I wrote to refresh the data in my workbook from our Data Warehouse, then refresh pivot tables and ultimately save one of the sheets as a PDF to my drive:

            ActiveWorkbook.RefreshAll
            Sheets("Karth").Select
            Range("B22").Select
            ActiveSheet.PivotTables("Karth_Appd_Wkly").PivotCache.Refresh
            Sheets("Start").Select
            Sheets("Karth").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            "K:\K\Analytics\Reports\Sales\SM Reports\SM Summary_Karth.pdf" _
            , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
            :=False, OpenAfterPublish:=False
            End Sub
        • To post as a guest, your comment is unpublished.
          Paul · 5 years ago
          Nice! Thanks for the reply, it also means a lot to me to know that my solution is the correct one. Cheers!