Skip to main content

Conas bileoga iolracha / uile-bhileoga a shábháil, a easpórtáil chuig comhaid csv nó téacs ar leithligh in Excel?

Agus Excel á úsáid agat, is féidir leat bileog oibre a shábháil de láimh mar chomhad csv nó téacs trí úsáid a bhaint as an bhfeidhm Save As. Mar sin féin, chun bileoga oibre iolracha nó gach bileog oibre i leabhar oibre a thiontú go csv scartha nó chuig comhaid téacs, conas is féidir leat a dhéanamh? San Airteagal seo, taispeánfaimid modhanna duit chun leathanaigh iolracha nó gach leathán a shábháil nó a thiontú go csv scartha nó chuig comhaid téacs.

Sábháil, easpórtáil nó tiontaigh gach bileog go csv nó comhad téacs le cód VBA
Sábháil, easpórtáil nó tiontú bileoga iolracha / uile go csv nó comhad téacs le Kutools for Excel


Sábháil, easpórtáil nó tiontaigh gach bileog go csv nó comhad téacs le cód VBA

Leis na cóid VBA thíos, is féidir leat gach bileog oibre i leabhar oibre a shábháil ar chomhaid scartha csv nó téacs. Déan mar a leanas le do thoil.

Gach bileog a easpórtáil nó a thiontú go comhaid csv

1. Brúigh Eile + F11 eochracha ag an am céanna chun an Feidhmchlár Bunúsach Amharc Microsoft fhuinneog.

2. Sa Feidhmchlár Bunúsach Amharc Microsoft fuinneog, cliceáil Ionsáigh > Modúil. Ansin cóipeáil agus greamaigh an cód seo a leanas isteach sa Modúil fhuinneog.

Cód VBA: Easpórtáil gach bileog go comhaid csv scartha

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. Brúigh an F5 eochair chun an cód a rith. Feicfidh tú go bhfuil gach comhad csv a onnmhairítear suite ar an Doiciméid fillteán. Féach an pictiúr:

Gach bileog a easpórtáil nó a thiontú go comhaid Téacs

Is féidir leis an gcód seo a leanas cabhrú leat gach bileog sa leabhar oibre a easpórtáil nó a thiontú go comhaid Téacs scartha.

Cód VBA: Easpórtáil gach bileog go comhaid Téacs scartha

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

Tá na comhaid Téacs a onnmhairítear le fáil ar an Doiciméid fillteán. Féach an pictiúr:


Sábháil, easpórtáil nó tiontú bileoga iolracha / uile go csv nó comhad téacs le Kutools for Excel

YIs féidir le ou bileoga iolracha nó bileoga uile a easpórtáil nó a thiontú go comhaid csv aonair, comhaid téacs nó formáid comhaid xls in Excel leis an Leabhar Oibre Scoilt fóntais de Kutools le haghaidh Excel.

Roimh iarratas a dhéanamh Kutools le haghaidh Excel, Le do thoil é a íoslódáil agus a shuiteáil ar dtús.

1. cliceáil Kutools Plus > Leabhar Oibre > Leabhar Oibre Scoilt. Féach an pictiúr:

2. Sa Leabhar Oibre Scoilt bosca dialóige:

  • 1). Más mian leat gach bileog a thiontú go comhaid csv nó téacs, coinnigh gach ainm bileog seiceáilte sa Ainm na bileoige oibre bosca; Mura dteastaíonn uait ach ilbhileoga a thiontú, coinnigh ort iad a sheiceáil agus déan dísheiceáil ar bhileoga eile nach dteastaíonn uait a thiontú.
  • 2). Sa Roghanna roinn, seiceáil an Ach amháin mar chineál bosca agus ansin roghnaigh Téacs Unicode (*. Txt) or CSV (Macintosh) (*. Csv) ón liosta anuas.
  • 3). Cliceáil ar an Scoilt cnaipe.

3. Sa Brabhsáil Chun Fillteán bosca dialóige, sonraigh fillteán chun na comhaid a onnmhairítear a shábháil, agus ansin cliceáil ar an OK cnaipe.

Anois athraítear gach bileog nó bileog sonraithe go comhaid scartha csv nó téacs, agus aimsítear iad ar an bhfillteán mar a shonraigh tú thuas.

  Más mian leat triail saor in aisce (30 lá) a bheith agat ar an bhfóntas seo, cliceáil le do thoil chun é a íoslódáil, agus ansin téigh chun an oibríocht a chur i bhfeidhm de réir na gcéimeanna thuas.


Sábháil, easpórtáil nó tiontú bileoga iolracha / uile go csv nó comhad téacs le Kutools for Excel

Uirlisí Táirgiúlachta Oifige is Fearr

🤖 Kutools AI Aide: anailís sonraí a réabhlóidiú bunaithe ar: Forghníomhú Chliste   |  Gin Cód  |  Cruthaigh Foirmlí Saincheaptha  |  Anailís a dhéanamh ar Sonraí agus Cairteacha a Ghin  |  Feidhmeanna Kutools a agairt...
Gnéithe Coitianta: Faigh, Aibhsigh nó Aithnigh Dúblaigh   |  Scrios Sraitheanna Bána   |  Comhcheangail Colúin nó Cealla gan Sonraí a Chailleadh   |   Babhta gan Foirmle ...
Cuardaigh Super: Ilchritéir VLookup    VLookup Illuachanna  |   VLookup Trasna Ilbhileoga   |   Amharc doiléir ....
Liosta anuas Casta: Go tapa Cruthaigh Liosta Anuas   |  Liosta anuas Cleithiúnach   |  Liosta Buail Isteach Ilroghnacha ....
Bainisteoir Colún: Cuir Líon Sonrach Colún leis  |  Colúin Bog  |  Scoránaigh Stádas Infheictheachta na gColún Ceilte  |  Déan comparáid idir Raonta & Colúin ...
Gnéithe Réadmhaoin: Fócas Eangaí   |  Amharc Dearaidh   |   Barra Mór na Foirmle    Leabhar Oibre & Bainisteoir Bileog   |  Leabharlann Acmhainní (Uaththéacs)   |  Piocálaí Dáta   |  Comhcheangail Bileoga Oibre   |  Criptigh/Díchriptigh Cealla    Seol Ríomhphost trí Liosta   |  Scagaire Super   |   Scagaire Speisialta (scagaire trom/iodálach/stailc tríd...) ...
Barr 15 Uirlisí12 Téacs uirlisí (Cuir Téacs, Bain Carachtair,...)   |   50 + Cairt cineálacha (Cairt Gantt,...)   |   40+ Praiticiúil Foirmlí (Ríomh aois bunaithe ar lá breithe,...)   |   19 Insertion uirlisí (Cuir isteach Cód QR, Ionsáigh Pictiúr ón gCosán,...)   |   12 Tiontú uirlisí (Uimhreacha le Focail, Comhshó Airgeadra,...)   |   7 Cumaisc & Scoilt uirlisí (Sraitheanna Comhcheangail Casta, Cealla Scoilt,...)   |   ... agus eile

Supercharge Do Scileanna Excel le Kutools le haghaidh Excel, agus Éifeachtúlacht Taithí Cosúil Ná Roimhe. Kutools le haghaidh Excel Tairiscintí Níos mó ná 300 Ardghnéithe chun Táirgiúlacht a Treisiú agus Sábháil Am.  Cliceáil anseo chun an ghné is mó a theastaíonn uait a fháil ...

Tuairisc


Tugann Tab Oifige comhéadan Tabbed chuig Office, agus Déan Do Obair i bhfad Níos Éasca

  • Cumasaigh eagarthóireacht agus léamh tabbed i Word, Excel, PowerPoint, Foilsitheoir, Rochtain, Visio agus Tionscadal.
  • Oscail agus cruthaigh cáipéisí iolracha i gcluaisíní nua den fhuinneog chéanna, seachas i bhfuinneoga nua.
  • Méadaíonn do tháirgiúlacht 50%, agus laghdaíonn sé na céadta cad a tharlaíonn nuair luch duit gach lá!
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