Skip to main content

Conas baisc ilchomhaid Excel a thiontú go comhaid CSV in Excel?

In Excel, is féidir linn an leabhar oibre a thiontú go comhad CSV leis an bhfeidhm Save as, ach an bhféadfá a fhios a bheith agat conas baisc ilchomhaid Excel a thiontú go comhaid CSV ar leithligh? San Airteagal seo, tugaim isteach cód VBA chun gach comhad Excel i bhfillteán a thiontú go comhaid CSV in Excel.

Baisc comhaid Excel d’fhillteán a thiontú go comhaid CSV le VBA

Tiontaigh bileoga de leabhar oibre i gcomhaid CSV ar leithligh le Kutools for Excelsmaoineamh maith3


Baisc comhaid Excel d’fhillteán a thiontú go comhaid CSV le VBA

In Excel, níl aon fheidhm ionsuite ann chun an post seo a réiteach go tapa seachas VBA.

1. Cumasaigh Excel, agus brúigh Alt + F11 eochracha oscailte Microsoft Visual Basic d’Fheidhmchláir fhuinneog.

2. cliceáil Ionsáigh > Modúil chun Modúl nua a chruthú.

3. Cóipeáil thíos an cód agus greamaigh iad chuig fuinneog nua an Mhodúil.

VBA: Baisc comhaid Excel a thiontú go CSV

Sub WorkbooksSaveAsCsvToFolder()

'UpdatebyExtendoffice20181031

Dim xObjWB As Workbook

Dim xObjWS As Worksheet

Dim xStrEFPath As String

Dim xStrEFFile As String

Dim xObjFD As FileDialog

Dim xObjSFD As FileDialog

Dim xStrSPath As String

Dim xStrCSVFName As String

Dim xS  As String

    Application.ScreenUpdating = False

    Application.EnableEvents = False

    Application.Calculation = xlCalculationManual

    Application.DisplayAlerts = False

    On Error Resume Next

Set xObjFD = Application.FileDialog(msoFileDialogFolderPicker)

    xObjFD.AllowMultiSelect = False

    xObjFD.Title = "Kutools for Excel - Select a folder which contains Excel files"

    If xObjFD.Show <> -1 Then Exit Sub

    xStrEFPath = xObjFD.SelectedItems(1) & "\"

    Set xObjSFD = Application.FileDialog(msoFileDialogFolderPicker)

 
    xObjSFD.AllowMultiSelect = False

    xObjSFD.Title = "Kutools for Excel - Select a folder to locate CSV files"

    If xObjSFD.Show <> -1 Then Exit Sub

    xStrSPath = xObjSFD.SelectedItems(1) & "\"


    xStrEFFile = Dir(xStrEFPath & "*.xls*")


    Do While xStrEFFile <> ""

       xS = xStrEFPath & xStrEFFile

        Set xObjWB = Application.Workbooks.Open(xS)

        xStrCSVFName = xStrSPath & Left(xStrEFFile, InStr(1, xStrEFFile, ".") - 1) & ".csv"

        xObjWB.SaveAs Filename:=xStrCSVFName, FileFormat:=xlCSV

        xObjWB.Close savechanges:=False

        xStrEFFile = Dir

  Loop

    Application.Calculation = xlCalculationAutomatic

    Application.EnableEvents = True

    Application.ScreenUpdating = True

    Application.DisplayAlerts = True

End Sub

4. Brúigh F5 eochair, roghnaigh san fhillteán tá na comhaid Excel a theastaíonn uait a thiontú go comhaid CSV sa chéad dialóg popping.
baisc doc go csv 1

5. cliceáil OK, ansin sa dara dialóg popping, roghnaigh an fillteán chun na comhaid CSV a chur.
baisc doc go csv 2

6. cliceáil OK, anois tá na comhaid Excel san fhillteán tiontaithe go comhaid CSV agus sábháladh iad i bhfillteán eile.
baisc doc go csv 3


Tiontaigh bileoga de leabhar oibre i gcomhaid CSV ar leithligh le Kutools for Excel

Mar is eol dúinn, ní féidir linn an leabhar oibre iomlán a thiontú go comhad CSV amháin in Excel lena fheidhm Save As. Ach i roinnt uaireanta, ba mhaith leat an bhileog aonair a thiontú go comhad CSV, sa chás seo, an Leabhar Oibre Scoilt fóntais de Kutools le haghaidh Excel Is féidir cabhrú leat.

Kutools le haghaidh Excel, le níos mó ná 300 feidhmeanna úsáideacha, déanann sé do phoist níos éasca. 

Tar éis a shuiteáil Kutools for Excel, déan mar atá thíos le do thoil:Download Kutools Íoslódáil saor in aisce do Excel Anois!)

1. Cumasaigh an leabhar oibre a theastaíonn uait a bhileoga a thiontú mar chomhaid CSV ar leithligh, cliceáil Kutools Plus > Leabhar Oibre > Leabhar Oibre Scoilt.
baisc doc go csv 4

2. Sa Leabhar Oibre Scoilt dialóg, seiceáil ainm na bileoige a theastaíonn uait a roinnt (déantar gach bileog a sheiceáil de réir réamhshocraithe), seiceáil Ach amháin mar cineál, roghnaigh CSV (Macintosh) (* .CSV) ón liosta anuas.
baisc doc go csv 5

3. cliceáil Scoilt a pop amach a Brabhsáil Chun Fillteán dialóg, roghnaigh nó cruthaigh fillteán chun na comhaid CSV a chur.
baisc doc go csv 6

4. cliceáil OK, anois tá an leabhar oibre roinnte mar chomhaid CSV ar leithligh.
baisc doc go csv 7

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 (37)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Thank you, lifesaver, I have no coding experience but this seems to work for my purposes perfectly.

Is it possible to set the directory for the read xls and write csv so that you don't have to select it each time? My files are being written to the same location each day automatically and I'm trying to automate this conversion to csv as much as I can.

Thanks,
This comment was minimized by the moderator on the site
This is a great peace of coding, but I just realised that it is inverting the dates for me. (we are in UK) and when the date shows 23/03/78 in the CSV the date comes out as 3/23/78.

Is doesn't happen to all lives. Eg if the date was showing 1/2/11 it would stay the same. But if it was 01/02/11 it would chnage to 02/01/11

Any suggestions?
This comment was minimized by the moderator on the site
Batch script not accept unicode character in file name or in work sheet. I've changed
xObjWB.SaveAs Filename:=xStrCSVFName, FileFormat:=[b]xlCSV[/b]


to

xObjWB.SaveAs Filename:=xStrCSVFName, FileFormat:=[b]xlCSVUTF8[/b]. But [b]xlCSVUTF8[/b] seems not supported in older excel version (before 2016)


Batch script not support files in recursive folders too.
This comment was minimized by the moderator on the site
Hallo,

ich habe den VBA-Code vor einem Jahr ohne Probleme angewendet. Jetzt funktioniert es nicht mehr.
Es gibt einen Laufzeitfehler 1004 mit dem Hinweis: "Die Methode 'calculation' für das Objekt '_Application' ist fehlgeschlagen."

Debuggen verweist auf die Zeile "Application.Calculation = xlCalculationManual".

Ich würde mich sehr freuen, wenn jemand weiterhelfen könnte.

LG, Max
This comment was minimized by the moderator on the site
Hi, Gast, pleae check if the code you copied is correct firstly, there is no "_" in the code. If you have checked all code is correct, you can remove the code line
Application.Calculation = xlCalculationManual then try again. Please notice that there are two lines Application.Calculation = xlCalculationManual in the code.
This comment was minimized by the moderator on the site
Hallo,

vor einem Jahr habe ich den VBA-Code ohne Probleme ausgeführt. Heute wollte ich es nochmal versuchen, leider gibt es einen Laufzeitfehler 1004 mit dem Hinweis
"Die Methode 'Calculation' ist für Objekt '_Application' fehlgeschlagen."

Debuggen verweist auf folgende Zeile:
Application.Calculation = xlCalculationManual

Kann jemand weiterhelfen?

LG, Max
This comment was minimized by the moderator on the site
Hi,
I'm facing some problems when using the script
Ho can I change the delimiter in the script because the delimiter in csv output is in comma (,)
I need the delimiter not in comma because my datasets consist a lot of commas.


Thank you
This comment was minimized by the moderator on the site
Ajouter Local:=True à cette ligne:
xObjWB.SaveAs Filename:=xStrCSVFName, FileFormat:=xlCSV, Local:=True

Permet de prendre le séparateur de votre système, moi c'est point-virgule ;
This comment was minimized by the moderator on the site
Hi, How can i change the delimiter ?
In the script above, the delimiter is comma (,).
Thank you :D
This comment was minimized by the moderator on the site
2019버전입니다.
게시글 그대로 실행해봤지만 아무것도 일어나지 않았습니다 ..
This comment was minimized by the moderator on the site
Hi, YOY, I have tested the VBA in Professional Plus Excel 2019, it works smoothly and correctly. Should you give me more details about your files, such as detailed verison, the contents of files you want to convert?
This comment was minimized by the moderator on the site
Bom Dia!!

muito top esse codigo, porem estou com o problema abaixo

Tem como salvar em formato "CSV (separado por vírgulas) (*.csv)", pois ao executar esse código meus arquivos ficam com "," no formato que eu preciso eles não ficam com essa vírgula
This comment was minimized by the moderator on the site
Same issue with me. Running latest office 365 but nothing happens after setting the two folders dialog boxes.
This comment was minimized by the moderator on the site
Hi, Doc SJ, thanks for your reminder, I have check the VBA code, it has some issues in Office 365, now I have updated the VBA, please try it again.
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