Skip i'r prif gynnwys

Sut i arbed, allforio taflenni lluosog / pob taflen i wahanu ffeiliau csv neu destun yn Excel?

Wrth ddefnyddio Excel, gallwch gadw taflen waith â llaw fel csv neu ffeil testun trwy ddefnyddio'r swyddogaeth Cadw Fel. Fodd bynnag, i drosi taflenni gwaith lluosog neu'r cyfan mewn llyfr gwaith yn ffeiliau csv neu destun ar wahân, sut allwch chi wneud? Yn yr erthygl hon, byddwn yn dangos dulliau i chi o gadw neu drosi dalen luosog neu bob tudalen yn ffeiliau csv neu destun ar wahân.

Cadw, allforio neu drosi pob dalen i csv neu ffeil testun gyda chod VBA
Cadw, allforio neu drosi dalen lluosog / pob dalen i csv neu ffeil testun gyda Kutools ar gyfer Excel


Cadw, allforio neu drosi pob dalen i csv neu ffeil testun gyda chod VBA

Gyda'r codau VBA isod, gallwch arbed yr holl daflenni gwaith mewn llyfr gwaith i ffeiliau csv neu destun sydd wedi'u gwahanu. Gwnewch fel a ganlyn.

Allforio neu drosi pob dalen yn ffeiliau csv

1. Gwasgwch Alt + F11 allweddi ar yr un pryd i agor y Cymhwysiad Sylfaenol Gweledol Microsoft ffenestr.

2. Yn y Cymhwysiad Sylfaenol Gweledol Microsoft ffenestr, cliciwch Mewnosod > Modiwlau. Yna copïwch a gludwch y cod canlynol i'r Modiwlau ffenestr.

Cod VBA: Allforiwch bob dalen i ffeiliau csv sydd wedi'u gwahanu

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. Gwasgwch y F5 allwedd i redeg y cod. Fe welwch fod yr holl ffeiliau csv a allforiwyd wedi'u lleoli ar y dogfennau ffolder. Gweler y screenshot:

Allforio neu drosi pob dalen yn ffeiliau Testun

Gall y cod canlynol eich helpu i allforio neu drosi'r holl daflenni yn y llyfr gwaith i ffeiliau Testun sydd wedi'u gwahanu.

Cod VBA: Allforiwch bob dalen i ffeiliau Testun sydd wedi'u gwahanu

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

Mae'r ffeiliau Testun a allforiwyd hefyd i'w gweld ar y dogfennau ffolder. Gweler y screenshot:


Cadw, allforio neu drosi dalen lluosog / pob dalen i csv neu ffeil testun gyda Kutools ar gyfer Excel

Ygall ou allforio neu drosi dalennau lluosog neu bob dalen yn gyflym i ffeiliau csv unigol, ffeiliau testun neu fformat ffeiliau xls yn Excel gyda'r Llyfr Gwaith Hollti cyfleustodau Kutools ar gyfer Excel.

Cyn gwneud cais Kutools ar gyfer Excel, os gwelwch yn dda ei lawrlwytho a'i osod yn gyntaf.

1. Cliciwch Kutools Byd Gwaith > Llyfr Gwaith > Llyfr Gwaith Hollti. Gweler y screenshot:

2. Yn y Llyfr Gwaith Hollti blwch deialog:

  • 1). Os ydych chi am drosi'r holl daflenni yn ffeiliau csv neu destun, dim ond cadw enwau pob dalen yn y Enw'r daflen waith blwch; Os ydych chi am drosi dalennau lluosog yn unig, daliwch i'w gwirio a mynd i ddad-dicio dalenni eraill nad ydych chi am eu trosi.
  • 2). Yn y Dewisiadau adran, edrychwch ar y Cadw fel math blwch ac yna dewis Testun Unicode (*. Txt) or CSV (Macintosh) (*. Csv) o'r rhestr ostwng.
  • 3). Cliciwch y Hollti botwm.

3. Yn y Porwch Am Ffolder blwch deialog, nodwch ffolder i achub y ffeiliau a allforiwyd, ac yna cliciwch ar y OK botwm.

Nawr mae'r holl daflenni neu daflenni penodedig yn cael eu trosi'n ffeiliau csv neu destun wedi'u gwahanu, ac wedi'u lleoli ar y ffolder fel y nodwyd gennych uchod.

  Os ydych chi am gael treial am ddim (30 diwrnod) o'r cyfleustodau hwn, cliciwch i'w lawrlwytho, ac yna ewch i gymhwyso'r llawdriniaeth yn ôl y camau uchod.


Cadw, allforio neu drosi dalen lluosog / pob dalen i csv neu ffeil testun gyda Kutools ar gyfer Excel

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser.  Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...

Disgrifiad


Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer

  • Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
  • Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
  • Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!
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