Direkt zum Inhalt

Wie speichere, exportiere ich mehrere / alle Blätter in separate CSV- oder Textdateien in Excel?

Wenn Sie Excel verwenden, können Sie ein Arbeitsblatt manuell als CSV- oder Textdatei speichern, indem Sie die Funktion Speichern unter verwenden. Wie können Sie jedoch mehrere oder alle Arbeitsblätter in einer Arbeitsmappe in getrennte CSV- oder Textdateien konvertieren? In diesem Artikel zeigen wir Ihnen Methoden zum Speichern oder Konvertieren mehrerer oder aller Blätter in getrennte CSV- oder Textdateien.

Speichern, exportieren oder konvertieren Sie alle Blätter in eine CSV- oder Textdatei mit VBA-Code
Speichern, exportieren oder konvertieren Sie mehrere / alle Blätter mit Kutools for Excel in eine CSV- oder Textdatei


Speichern, exportieren oder konvertieren Sie alle Blätter in eine CSV- oder Textdatei mit VBA-Code

Mit den folgenden VBA-Codes können Sie alle Arbeitsblätter in einer Arbeitsmappe in getrennten CSV- oder Textdateien speichern. Bitte gehen Sie wie folgt vor.

Exportieren oder konvertieren Sie alle Blätter in CSV-Dateien

1. Drücken Sie Andere + F11 Tasten gleichzeitig zum Öffnen der Microsoft Visual Basic-Anwendung Fenster.

2. In dem Microsoft Visual Basic-Anwendung Klicken Sie im Fenster Insert > Modul. Kopieren Sie dann den folgenden Code und fügen Sie ihn in das ein Modul Fenster.

VBA-Code: Exportieren Sie alle Blätter in getrennte CSV-Dateien

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. Drücken Sie die Taste F5 Schlüssel zum Ausführen des Codes. Sie sehen, dass sich alle exportierten CSV-Dateien auf der befinden Dokumente Mappe. Siehe Screenshot:

Exportieren oder konvertieren Sie alle Blätter in Textdateien

Der folgende Code kann Ihnen beim Exportieren oder Konvertieren aller Blätter in der Arbeitsmappe in getrennte Textdateien helfen.

VBA-Code: Exportieren Sie alle Blätter in getrennte Textdateien

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

Die exportierten Textdateien befinden sich ebenfalls auf der Dokumente Mappe. Siehe Screenshot:


Speichern, exportieren oder konvertieren Sie mehrere / alle Blätter mit Kutools for Excel in eine CSV- oder Textdatei

YMit dem können Sie schnell mehrere oder alle Blätter in einzelne CSV-Dateien, Textdateien oder XLS-Dateien in Excel exportieren oder konvertieren Arbeitsmappe teilen Nutzen von Kutools for Excel.

Vor der Bewerbung Kutools for Excel, Bitte Laden Sie es zuerst herunter und installieren Sie es.

1 Klicken Kutoolen Plus > Workbook > Arbeitsmappe teilen. Siehe Screenshot:

2. In dem Arbeitsmappe teilen Dialogbox:

  • 1). Wenn Sie alle Blätter in CSV- oder Textdateien konvertieren möchten, lassen Sie einfach alle Blattnamen im Feld aktiviert Name des Arbeitsblatts Box; Wenn Sie nur mehrere Blätter konvertieren möchten, überprüfen Sie sie weiter und deaktivieren Sie andere Blätter, die Sie nicht konvertieren möchten.
  • 2). In dem Optionen Abschnitt, überprüfen Sie die Speichern als Typ Feld und wählen Sie dann Unicode-Text (*. Txt) or CSV (Macintosh) (*. CSV) aus der Dropdown-Liste.
  • 3). Drücke den Split .

3. In dem Suche nach Ordner Geben Sie im Dialogfeld einen Ordner zum Speichern der exportierten Dateien an und klicken Sie dann auf OK .

Jetzt werden alle Blätter oder angegebenen Blätter in getrennte CSV- oder Textdateien konvertiert und befinden sich wie oben angegeben im Ordner.

  Wenn Sie eine kostenlose Testversion (30 Tage) dieses Dienstprogramms wünschen, Bitte klicken Sie, um es herunterzuladenund wenden Sie dann die Operation gemäß den obigen Schritten an.


Speichern, exportieren oder konvertieren Sie mehrere / alle Blätter mit Kutools for Excel in eine CSV- oder Textdatei

Beste Office-Produktivitätstools

🤖 Kutools KI-Assistent: Revolutionieren Sie die Datenanalyse basierend auf: Intelligente Ausführung   |  Code generieren  |  Erstellen Sie benutzerdefinierte Formeln  |  Analysieren Sie Daten und erstellen Sie Diagramme  |  Rufen Sie Kutools-Funktionen auf...
Beliebte Funktionen: Suchen, markieren oder identifizieren Sie Duplikate   |  Leere Zeilen löschen   |  Kombinieren Sie Spalten oder Zellen, ohne Daten zu verlieren   |   Runde ohne Formel ...
Super-Lookup: VLookup mit mehreren Kriterien    VLookup mit mehreren Werten  |   VLookup über mehrere Blätter hinweg   |   Unscharfe Suche ....
Erweiterte Dropdown-Liste: Erstellen Sie schnell eine Dropdown-Liste   |  Abhängige Dropdown-Liste   |  Mehrfachauswahl Dropdown-Liste ....
Spaltenmanager: Fügen Sie eine bestimmte Anzahl von Spalten hinzu  |  Spalten verschieben  |  Schalten Sie den Sichtbarkeitsstatus ausgeblendeter Spalten um  |  Vergleichen Sie Bereiche und Spalten ...
Ausgewählte Funktionen: Rasterfokus   |  Designansicht   |   Große Formelleiste    Arbeitsmappen- und Blattmanager   |  Ressourcen (Autotext)   |  Datumsauswahl   |  Arbeitsblätter kombinieren   |  Zellen verschlüsseln/entschlüsseln    Senden Sie E-Mails nach Liste   |  Superfilter   |   Spezialfilter (Filter fett/kursiv/durchgestrichen...) ...
Top 15 Toolsets12 Text Tools (Text hinzufügen, Zeichen entfernen, ...)   |   50+ Chart Typen (Gantt-Diagramm, ...)   |   40+ Praktisch Formeln (Berechnen Sie das Alter basierend auf dem Geburtstag, ...)   |   19 Einfügen Tools (QR-Code einfügen, Bild aus Pfad einfügen, ...)   |   12 Umwandlung (Conversion) Tools (Zahlen zu Wörtern, Currency Conversion, ...)   |   7 Zusammenführen & Teilen Tools (Erweiterte Zeilen kombinieren, Zellen teilen, ...)   |   ... und mehr

Verbessern Sie Ihre Excel-Kenntnisse mit Kutools für Excel und erleben Sie Effizienz wie nie zuvor. Kutools für Excel bietet über 300 erweiterte Funktionen, um die Produktivität zu steigern und Zeit zu sparen.  Klicken Sie hier, um die Funktion zu erhalten, die Sie am meisten benötigen ...

Beschreibung


Office Tab Bringt die Oberfläche mit Registerkarten in Office und erleichtert Ihnen die Arbeit erheblich

  • Aktivieren Sie das Bearbeiten und Lesen von Registerkarten in Word, Excel und PowerPoint, Publisher, Access, Visio und Project.
  • Öffnen und erstellen Sie mehrere Dokumente in neuen Registerkarten desselben Fensters und nicht in neuen Fenstern.
  • Steigert Ihre Produktivität um 50 % und reduziert jeden Tag Hunderte von Mausklicks für Sie!
Comments (38)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi, thanks for the VBA, i have a problem with the VBA for export to text file, as the VBA run the txt file got generated, but the inside data is not exactly like the excel data, for example my data include character quotation mark, and the exported data became double quotation mark, plus the beginning and the ending of the text file there are quotation mark, here's the excel and the txt file that i meant :
excel : Start Chrome https://xxx/tap_inbox_sparepart_act.asp?proses_id=202300102027800&act=akseptoraksep"&"alasan=ok
text file : "Start Chrome https://xxx/tap_inbox_sparepart_act.asp?proses_id=202300102027800&act=akseptoraksep""&""alasan=ok"

Thanks in advanced :)
This comment was minimized by the moderator on the site
Hi Nicky,

I tested this code, but could not reproduce the problem in my case. And the file you provided didn't open. Can you upload your file using the "upload attachment" link below?
This comment was minimized by the moderator on the site
The VBA code works nicely. Equivalent C# code in a VSTO workbook project emits empty .csv files.


void SaveSomeWorksheetsAsCsvFiles() {
    string[] worksheetNames = new[] { "Sheet1", "Sheet2", "Sheet3" };
    foreach (var worksheet in worksheetNames.Select(_ => Globals.ThisWorkbook.Sheets[_] as Excel.Worksheet)) {
        worksheet.Copy();
        string fullName = @"C:\Users\....\Staging" + $".{worksheet.Name}.csv";
        this.SaveAs(fullName, XlFileFormat.xlCSV);
        Application.ActiveWorkbook.Saved = true;
        Application.ActiveWorkbook.Close();
    }
}
This comment was minimized by the moderator on the site
Hi Calvin,
We do not support programming languages other than VBA. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
Hi, thanks for the great code (Export all sheets to separated Text files), using it a lot. Just ran into a workbook where it won't work, debugger says line xWs.Copy is problem, popup says method copy of a workbook failed. Is there any restrictions concerning a worksheet name or something similar, like no merged cells etc..?

Thanks for a reply :)
This comment was minimized by the moderator on the site
HI BI,
Does your worksheet contain a pivot table? Can you provide us with your data for tesing? If you don't mind, upload your sample file here.
This comment was minimized by the moderator on the site
Hi, thanks for the great code it is awesome(Export all sheets to separated Text files)! Used it on many occasions but ran into a file where it won't work, debugger says runtime error 1004 and that method copy of a worksheet failed and marks line xWs.Copy. Is there any rule concerning a worksheet name that would not allow code to run?
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
how would I change the code to have it save in a different file format such as an xlsx? or ASCII.
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
Hi,
The first VBA code in this post can do you a favor.
This comment was minimized by the moderator on the site
Is there a way to use this code to export only a certain range to a .csv file of each sheet in a book?
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
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!
This comment was minimized by the moderator on the site
Hi Mirko,
Method in this article can do you a favor: https://trumpexcel.com/personal-macro-workbook/.
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
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.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations