Namig: drugi jeziki so prevedeni v Google. Lahko obiščete English različico te povezave.
Vpiši se
x
or
x
x
Registracija
x

or

Kako pretvoriti več datotek CSV v datoteke XLS (X) v Excelu?

Za pretvorbo datoteke CSV v datoteko XlS ali XLSX je zelo preprosto za vas z uporabo funkcije Save As. Vendar pa za pretvorbo več datotek CSV v datoteke XLS ali XLSX iz mape porabite veliko časa, saj jih ročno shranite po eno. Tukaj uvajam makro kodo, da hitro pretvorimo vse datoteke CSV v datoteke XLS (x) iz mape.

Batch pretvorite datoteke CSV v datoteke XlS (X) z makro kodo


Batch pretvorite datoteke CSV v datoteke XlS (X) z makro kodo


Če želite pretvoriti več datotek CSV iz ene mape v datoteke XLS (X), lahko storite kot spodaj:

Kutools za Excel, z več kot 120 priročne funkcije, olajšajo vaše delo.

1. Omogočite novo delovno knjižico, pritisnite Alt + F11 tipke za odpiranje Microsoft Visual Basic za aplikacije okno in kliknite Vstavi > Moduli. Prikaz slike:
doc batch convert cvs xls 1

Opombe: Prepričajte se, da so vse datoteke CSV, ki jih želite pretvoriti, zaprite.

2. Nato prilepite pod makro kodo v Moduli skripta in pritisnite F5 ključ za zagon kode.

VBA: spremeniti CSV v XLS

Sub CSVtoXLS()
'UpdatebyExtendoffice20170814
    Dim xFd As FileDialog
    Dim xSPath As String
    Dim xCSVFile As String
    Dim xWsheet As String
    Application.DisplayAlerts = False
    Application.StatusBar = True
    xWsheet = ActiveWorkbook.Name
    Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
    xFd.Title = "Select a folder:"
    If xFd.Show = -1 Then
        xSPath = xFd.SelectedItems(1)
    Else
        Exit Sub
    End If
    If Right(xSPath, 1) <> "\" Then xSPath = xSPath + "\"
    xCSVFile = Dir(xSPath & "*.csv")
    Do While xCSVFile <> ""
        Application.StatusBar = "Converting: " & xCSVFile
        Workbooks.Open Filename:=xSPath & xCSVFile
        ActiveWorkbook.SaveAs Replace(xSPath & xCSVFile, ".csv", ".xls", vbTextCompare), xlNormal
        ActiveWorkbook.Close
        Windows(xWsheet).Activate
        xCSVFile = Dir
    Loop
    Application.StatusBar = False
    Application.DisplayAlerts = True
End Sub

3. V pojavnem pogovornem oknu izberite ustrezno mapo, ki vsebuje datoteke CSV, ki jih želite pretvoriti. Prikaz slike:
doc batch convert cvs xls 2

4. klik OK, so bile vse datoteke CSV v izbrani mapi pretvorjene v datoteke XLS v njem.
doc batch convert cvs xls 3

Nasvet: Če želite datoteke CSV pretvoriti v datoteke XLSX, uporabite spodnjo kodo VBA.

VBA: Pretvori datoteke CSV v XLSX

Sub CSVtoXLS()
'UpdatebyExtendoffice20170814
    Dim xFd As FileDialog
    Dim xSPath As String
    Dim xCSVFile As String
    Dim xWsheet As String
    Application.DisplayAlerts = False
    Application.StatusBar = True
    xWsheet = ActiveWorkbook.Name
    Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
    xFd.Title = "Select a folder:"
    If xFd.Show = -1 Then
        xSPath = xFd.SelectedItems(1)
    Else
        Exit Sub
    End If
    If Right(xSPath, 1) <> "\" Then xSPath = xSPath + "\"
    xCSVFile = Dir(xSPath & "*.csv")
    Do While xCSVFile <> ""
        Application.StatusBar = "Converting: " & xCSVFile
        Workbooks.Open Filename:=xSPath & xCSVFile
        ActiveWorkbook.SaveAs Replace(xSPath & xCSVFile, ".csv", ".xls", vbTextCompare), xlWorkbookDefault
        ActiveWorkbook.Close
        Windows(xWsheet).Activate
        xCSVFile = Dir
    Loop
    Application.StatusBar = False
    Application.DisplayAlerts = True
End Sub


dobroIzvozni obseg v datoteko

Kutools za Excel 's Izvozi obseg v datoteko lahko izvozi ali shrani razpon, da ločijo datoteko kot
delovni zvezek, pdf, besedilo, csv ali besedilo.
klik Podjetje > Uvoz / izvoz > Izvozni obseg v datoteko.
doc izvozni obseg celice v datoteko

Relativni členi:


Priporočena orodja za produktivnost za Excel

zavihek kte 201905

Kutools za Excel vam pomaga, da vedno končate delo pred časom in izstopite iz množice

  • Več kot zmogljive napredne funkcije 300, zasnovane za 1500 delovne scenarije, ki povečujejo produktivnost z 70%, vam dajejo več časa za skrb za družino in uživanje v življenju.
  • Ne potrebujete več pomnilniških formul in VBA kod, od zdaj naprej pa dajate svojim možganom počitek.
  • Postanite strokovnjak za Excel v minutah 3, zapletene in ponavljajoče se operacije lahko opravite v nekaj sekundah,
  • Vsak dan zmanjšajte število operacij tipkovnice in miške, zdaj se poslovite od poklicnih bolezni.
  • 110,000 visoko učinkovite ljudi in 300 + svetovno priznanih podjetij izbiro.
  • Brezplačna preizkusna različica 60 dneva. 60-dnevno jamstvo vračila denarja. 2 let brezplačne nadgradnje in podpore.

Prinaša kartično brskanje in urejanje za Microsoft Office, veliko močnejši od zavihkov brskalnika

  • Office Tab je namenjen za Word, Excel, PowerPoint in druge Office aplikacije: Založnik, Dostop, Visio in Projekt.
  • Odprite in ustvarite več dokumentov v novih zavihkih istega okna in ne v novih oknih.
  • Z 50% poveča vašo produktivnost in vsak dan zmanjša na stotine klikov z miško!
Say something here...
symbols left.
You are guest ( Sign Up? )
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.
    Angel Alvarado · 18 days ago
    Thanks for providing the code. I modified the code to do the XLSX to CSV batch conversion. The code is provided below.


    Sub XLSXtoCSV()
    'UpdatebyExtendoffice20170814
    Dim xFd As FileDialog
    Dim xSPath As String
    Dim xCSVFile As String
    Dim xWsheet As String
    Application.DisplayAlerts = False
    Application.StatusBar = True
    xWsheet = ActiveWorkbook.Name
    Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
    xFd.Title = "Select a folder:"
    If xFd.Show = -1 Then
    xSPath = xFd.SelectedItems(1)
    Else
    Exit Sub
    End If
    If Right(xSPath, 1) <> "\" Then xSPath = xSPath + "\"
    xXLSXFile = Dir(xSPath & "*.xlsx")
    Do While xXLSXFile <> ""
    Application.StatusBar = "Converting: " & xXLSXFile
    Workbooks.Open Filename:=xSPath & xXLSXFile
    ActiveWorkbook.SaveAs Replace(xSPath & xXLSXFile, ".xlsx", ".csv", vbTextCompare), xlCSV
    ActiveWorkbook.Close
    Windows(xWsheet).Activate
    xXLSXFile = Dir
    Loop
    Application.StatusBar = False
    Application.DisplayAlerts = True
    End Sub
  • To post as a guest, your comment is unpublished.
    Sam · 19 days ago
    One small issue with this code is that some accuracy (number of decimals) can be lost when opening a csv and saving it as xlsx.
    The way to prevent this is to select all cells right after opening, set the number of decimal places to the desired amount (15 for me personally), and *then* saving as xlsx

    Otherwise, the xlsx has less detail (less accuracy in terms of decimals) than the original csv, which can lead to problems in some applications
  • To post as a guest, your comment is unpublished.
    Rose · 24 days ago
    this macro does not show my csv file
  • To post as a guest, your comment is unpublished.
    stb · 1 months ago
    Cool bit of code. Very useful. If I'm not mistaken the code for .xlsx looks the same as the .xls code.

    This line:
    ActiveWorkbook.SaveAs Replace(xSPath & xCSVFile, ".csv", ".xls", vbTextCompare), xlWorkbookDefault

    I assume it should be: ".csv" , ".xlsx", vbTextCompare etc.
    • To post as a guest, your comment is unpublished.
      iBrezel · 1 months ago
      I've changed the code so, described above; now the script works as expected: it generates xlsx files
  • To post as a guest, your comment is unpublished.
    pramod koliar · 3 months ago
    Great Script after searching all other script available in google. Can anybody help how to modify this script by specifying a folder location in local drive instead of allowing it to open the dialog box as i am actually automating the system. Thanks in advance