Ana içeriğe atla

Excel'de birden çok CSV dosyasını XLS (X) dosyalarına toplu olarak nasıl dönüştürebilirim?

Farklı Kaydet özelliğini uygulayarak bir CSV dosyasını XlS veya XLSX dosyasına dönüştürmek sizin için çok kolaydır. Ancak, birden çok CSV dosyasını bir klasörden XLS veya XLSX dosyalarına dönüştürmek, tek tek manuel olarak kaydederek zaman alıcıdır. Burada, tüm CSV dosyalarını bir klasörden XLS (x) dosyalarına hızlı bir şekilde toplu olarak dönüştürmek için bir makro kodu sunuyoruz.

Makro koduyla CSV dosyalarını XlS (X) dosyalarına toplu dönüştürün


Makro koduyla CSV dosyalarını XlS (X) dosyalarına toplu dönüştürün

Birden çok CSV dosyasını bir klasörden XLS (X) dosyalarına dönüştürmek için aşağıdaki adımları uygulayabilirsiniz:

1. Yeni bir çalışma kitabını etkinleştirin, Alt + F11 açmak için anahtarlar Uygulamalar için Microsoft Visual Basic pencere ve tıklayın Ekle > modül. Ekran görüntüsüne bakın:
doc toplu dönüştürme cvs xls 1

not: Dönüştürmek istediğiniz tüm CSV dosyalarının kapalı olduğundan emin olun.

2. Ardından makro kodunun altına yapıştırın. modül komut dosyası ve basın F5 kodu çalıştırmak için anahtar.

VBA: CSV'yi XLS'ye dönüştürme

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. Açılan iletişim kutusunda, dönüştürmek istediğiniz CSV dosyalarını içeren belirtilen klasörü seçin. Ekran görüntüsüne bakın:
doc toplu dönüştürme cvs xls 2

4. tık OK, seçili klasördeki tüm CSV dosyaları içindeki XLS dosyalarına dönüştürülmüştür.
doc toplu dönüştürme cvs xls 3

Bahşiş: CSV dosyalarını XLSX dosyalarına dönüştürmek istiyorsanız aşağıdaki VBA kodunu kullanırsınız.

VBA: CSV dosyalarını XLSX'e dönüştürün

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", ".xlsx", vbTextCompare), xlWorkbookDefault
        ActiveWorkbook.Close
        Windows(xWsheet).Activate
        xCSVFile = Dir
    Loop
    Application.StatusBar = False
    Application.DisplayAlerts = True
End Sub

XLS / Word / PDF veya diğer format dosyalarını bir defada ayırmak için bir sayfa aralığını hızlı bir şekilde dönüştürün veya dışa aktarın

Normalde, Excel bir aralığı hızlı bir şekilde dışa aktarma veya CSV veya Excel dosyası olarak kaydetme seçeneği sunmaz. Bir dizi veriyi Excel'de CSV veya çalışma kitabı olarak kaydetmek istiyorsanız, bunu yapmak için bir VBA Makrosu kullanmanız veya aralığı panoya kopyalayıp yeni bir çalışma kitabına yapıştırmanız ve ardından çalışma kitabını CSV olarak kaydetmeniz gerekebilir veya Çalışma kitabı. Kutools for Excel Excel'i artırır Aralığı Dosyaya Aktar aşağıdaki işlemleri hızlı bir şekilde gerçekleştirmek isteyen Excel kullanıcıları için yardımcı program :  30 günlük tam özellikli ücretsiz deneme için tıklayın!
doc hücre aralığını dosyaya aktar
 
Kutools for Excel: 300'den fazla kullanışlı Excel eklentisi ile 30 günde sınırlama olmaksızın ücretsiz olarak deneyin.

İlgili Makaleler:

En İyi Ofis Üretkenlik Araçları

🤖 Kutools AI Yardımcısı: Aşağıdakilere dayalı olarak veri analizinde devrim yaratın: Akıllı Yürütme   |  Kodunu oluşturun  |  Özel Formüller Oluşturun  |  Verileri Analiz Edin ve Grafikler Oluşturun  |  Kutools İşlevlerini Çağır...
Popüler Özellikler: Yinelenenleri Bul, Vurgula veya Tanımla   |  Boş Satırları Sil   |  Veri Kaybı Olmadan Sütunları veya Hücreleri Birleştirin   |   Formülsüz Tur ...
Süper Arama: Çoklu Ölçütlü VLookup    Çoklu Değer VLookup  |   Birden Çok Sayfada VLookup   |   Bulanık Arama ....
Gelişmiş Açılır Liste: Hızla Açılır Liste Oluşturun   |  Bağımlı Açılır Liste   |  Çoklu Seçim Açılır Liste ....
Sütun Yöneticisi: Belirli Sayıda Sütun Ekleme  |  Sütunları Taşı  |  Gizli Sütunların Görünürlük Durumunu Değiştir  |  Aralıkları ve Sütunları Karşılaştırın ...
Öne Çıkan Özellikler: Izgara Odağı   |  Tasarım görünümü   |   Büyük Formül Çubuğu    Çalışma Kitabı ve Sayfa Yöneticisi   |  Kaynak Kütüphanesi (Otomatik metin)   |  Tarih Seçici   |  Çalışma Sayfalarını Birleştirin   |  Hücreleri Şifrele/Şifresini Çöz    E-postaları Listeye Göre Gönder   |  Süper Filtre   |   Özel Filtre (kalın/italik/üstü çizili filtre...) ...
En İyi 15 Araç Seti12 Metin Tools (Metin ekle, Karakterleri Kaldır, ...)   |   50+ Grafik Türleri (Gantt şeması, ...)   |   40+ Pratik Formüller (Yaşı doğum gününe göre hesapla, ...)   |   19 sokma Tools (QR Kodunu Girin, Yoldan Resim Ekle, ...)   |   12 Dönüştürme Tools (Sayılardan Kelimelere, Para Birimi Dönüştürme, ...)   |   7 Birleştir ve Böl Tools (Gelişmiş Kombine Satırları, Bölünmüş hücreler, ...)   |   ... ve dahası

Kutools for Excel ile Excel Becerilerinizi Güçlendirin ve Daha Önce Hiç Olmadığı Gibi Verimliliği Deneyimleyin. Kutools for Excel, Üretkenliği Artırmak ve Zamandan Tasarruf Etmek için 300'den Fazla Gelişmiş Özellik Sunar.  En Çok İhtiyacınız Olan Özelliği Almak İçin Buraya Tıklayın...

Açıklama


Office Tab, Office'e Sekmeli Arayüz Getirir ve İşinizi Çok Daha Kolay Hale Getirir

  • Word, Excel, PowerPoint'te sekmeli düzenlemeyi ve okumayı etkinleştirin, Publisher, Access, Visio ve Project.
  • Yeni pencereler yerine aynı pencerenin yeni sekmelerinde birden çok belge açın ve oluşturun.
  • Üretkenliğinizi% 50 artırır ve her gün sizin için yüzlerce fare tıklamasını azaltır!
Comments (41)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Realmente me funcionó, muchas gracias!
Rated 5 out of 5
This comment was minimized by the moderator on the site
Thanks for this macro code! It works and converts my csv's to xlsx and saves me time. The only problem I have is that the column name in cell A1 is gone.
I have to add this back to all the xlsx files because this is needed for further scripts I run on the xlsx files.
This comment was minimized by the moderator on the site
Hi, Cyril, I have test the code again, the column name in A1 is still saved in the xlsx files.
This comment was minimized by the moderator on the site
Not working. Copied same code.. Pop up comes to select csv but even though there are csv files in the folder, non appears in the browse list. any reason why?
This comment was minimized by the moderator on the site
Buenos dias compañeros

Adiciona a lo que hace el script, quisiera poder convertir inmediatamente el texto en columnas, por la opción que no es delimitado por ningún tipo de caracter, adicional los tamaños de las columnas son diferentes. Vale la pena aclarar que si tomo cada archivo por separado y le aplico la opción de texto en columnas, bajo esa opción los puedo convertir sin problemas, abriéndolos uno por uno, pero si grabo esa macro y le aplico la misma macro a todos, inclusive usando la opción de "USAR REFERENCIAS RELATIVAS", no hace el proceso bien, porque el graba las posiciones de la delimitación del archivo que uso de ejemplo, pero necesito que lo aplique nuevo a cada archivo, es decir, como si abriera cada archivo nuevo y le hiciera manualmente la opción de delimitación y no aplique los valores de ubicación de las columnas identificados en el archivo ejemplo.

Ya inserte esa opcion en este archivo, sin embargo pasa lo que indico en la lineas arriba, solo requiero saber como puedo hacer para aplicar la conversion a cada archivo, aplicando la delimitacion del campo como su fuera un archivo nuevo.


Workbooks.Open Filename:=xSPath & xCSVFile
ActiveWorkbook.SaveAs Replace(xSPath & xCSVFile, ".csv", ".xlsx", vbTextCompare), xlWorkbookDefault

ESTA PARTE ES LA QUE AGREGUE APLICANDO EL FORMATO DEL TEXTO A COLUMNAS

StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(18 _
, 1), Array(38, 1)), TrailingMinusNumbers:=True
ActiveCell.Cells.Select
ActiveCell.Cells.EntireColumn.AutoFit
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveWorkbook.Save

HASTA AQUI AGREGUE YO

ActiveWorkbook.Close
Windows(xWsheet).Activate
xCSVFile = Dir

Loop
Application.StatusBar = False
Application.DisplayAlerts = True
End Sub

No se si me hago explicar bien, pero es mi problema.
This comment was minimized by the moderator on the site
yes it's not work.
This comment was minimized by the moderator on the site
How would I incorporate code into the XLSX batch file routine to semicolon separate the data into separate columns? The code shared converts the file from a .csv to a .xlsx, but it doesn't separate the data into separate columns.
This comment was minimized by the moderator on the site
This is working for me, but the file extension is not changing. Any tips?
This comment was minimized by the moderator on the site
I had the same problem. If your source file has an extention in capital letters (.CSV) it doesnt work. Just replace .csv to .CSV in the code in line 22 and then it should work. Well, at least for me it did.
This comment was minimized by the moderator on the site
Same for me -- all files remain .csv.
This comment was minimized by the moderator on the site
All csv files you choose have been save as new excel files, the original files (csv) do not change, there are new excel files with same contents existing.
This comment was minimized by the moderator on the site
I get an error "Object variable or with block variable not set" for this line:
xFd.Title = "/Users/[my.name]/Documents/[myFolder]" >> this is the path of a particular folder on my computer where I'm doing the conversion (the folder has a bunch of csv files inside)

Am I doing something wrong here?
This comment was minimized by the moderator on the site
You have an error on line 22 of the csv to xlsx
With Error - ActiveWorkbook.SaveAs Replace(xSPath & xCSVFile, ".csv", ".xls", vbTextCompare), xlWorkbookDefault
Corrected - ActiveWorkbook.SaveAs Replace(xSPath & xCSVFile, ".csv", ".xslx", vbTextCompare), xlWorkbookDefault
This comment was minimized by the moderator on the site
Thanks for your reminder, I have updated it, thanks again.
This comment was minimized by the moderator on the site
great article. How can I, save all the converted files in a new location? Can you please update the code and send it to me. Like allowing the user to choose his destination folder.


Thanks
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