Loncat ke daftar isi utama

Bagaimana cara mengimpor banyak file teks ke beberapa lembar?

Misalkan, ada beberapa file teks dalam folder komputer Anda, sekarang, Anda ingin mengimpor file teks ini ke buku kerja Excel, dan menempatkan setiap file teks ke dalam lembar kerja terpisah. Menyalin dan menempelkan setiap file teks ke lembar kerja satu per satu akan membuang banyak waktu, di sini, saya dapat berbicara tentang beberapa trik bagi Anda untuk mengatasi masalah ini.

Impor beberapa file teks ke lembar kerja terpisah dengan kode VBA

Pisahkan buku kerja menjadi beberapa file teks / pdf / csv / xlsx terpisah dengan Kutools for Excel


panah gelembung kanan biru Impor beberapa file teks ke lembar kerja terpisah dengan kode VBA

Kode VBA berikut dapat membantu Anda mengimpor setiap file teks ke dalam lembar terpisah dalam workbook baru sekaligus, lakukan hal berikut:

1. Tahan ALT + F11 kunci di Excel untuk membuka file Microsoft Visual Basic untuk Aplikasi jendela.

2. Klik Menyisipkan > Modul, dan tempel kode berikut di Modul Jendela.

Kode VBA: Impor beberapa file teks ke lembar kerja terpisah:

Sub CombineTextFiles()
'updateby Extendoffice
    Dim xFilesToOpen As Variant
    Dim I As Integer
    Dim xWb As Workbook
    Dim xTempWb As Workbook
    Dim xDelimiter As String
    Dim xScreen As Boolean
    On Error GoTo ErrHandler
    xScreen = Application.ScreenUpdating
    Application.ScreenUpdating = False
    xDelimiter = "|"
    xFilesToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt", , "Kutools for Excel", , True)
    If TypeName(xFilesToOpen) = "Boolean" Then
        MsgBox "No files were selected", , "Kutools for Excel"
        GoTo ExitHandler
    End If
    I = 1
    Set xTempWb = Workbooks.Open(xFilesToOpen(I))
    xTempWb.Sheets(1).Copy
    Set xWb = Application.ActiveWorkbook
    xTempWb.Close False
    xWb.Worksheets(I).Columns("A:A").TextToColumns _
      Destination:=Range("A1"), DataType:=xlDelimited, _
      TextQualifier:=xlDoubleQuote, _
      ConsecutiveDelimiter:=False, _
      Tab:=False, Semicolon:=False, _
      Comma:=False, Space:=False, _
      Other:=True, OtherChar:="|"
    Do While I < UBound(xFilesToOpen)
        I = I + 1
        Set xTempWb = Workbooks.Open(xFilesToOpen(I))
        With xWb
            xTempWb.Sheets(1).Move after:=.Sheets(.Sheets.Count)
            .Worksheets(I).Columns("A:A").TextToColumns _
              Destination:=Range("A1"), DataType:=xlDelimited, _
              TextQualifier:=xlDoubleQuote, _
              ConsecutiveDelimiter:=False, _
              Tab:=False, Semicolon:=False, _
              Comma:=False, Space:=False, _
              Other:=True, OtherChar:=xDelimiter
        End With
    Loop
ExitHandler:
    Application.ScreenUpdating = xScreen
    Set xWb = Nothing
    Set xTempWb = Nothing
    Exit Sub
ErrHandler:
    MsgBox Err.Description, , "Kutools for Excel"
    Resume ExitHandler
End Sub

3. Setelah menempelkan kode di atas, tekan F5 kunci untuk menjalankan kode ini, dan di jendela yang muncul, tentukan folder yang berisi file teks, pergi ke folder untuk memilih file teks yang ingin Anda impor ke lembar kerja, lihat tangkapan layar:

doc mengimpor beberapa file teks 1

4. Lalu klik Open tombol, semua file teks yang dipilih telah diimpor ke buku kerja baru dan setiap file terletak di satu lembar kerja secara individual.

5. Akhirnya, Anda bisa menyimpan buku kerja baru sesuai kebutuhan.


panah gelembung kanan biru Pisahkan buku kerja menjadi beberapa file teks / pdf / csv / xlsx terpisah dengan Kutools for Excel

Terkadang, Anda mungkin perlu melakukan beberapa operasi yang berlawanan dari tugas di atas, artinya, Anda perlu memisahkan buku kerja untuk memisahkan file teks. Kutools untuk Excel'S Pisahkan Buku Kerja utilitas dapat membantu Anda menyelesaikan pekerjaan ini dengan cepat dan mudah.

Kutools untuk Excel : dengan lebih dari 300 add-in Excel yang praktis, gratis untuk dicoba tanpa batasan dalam 30 hari

Setelah menginstal Kutools untuk Excel, lakukan hal berikut :( Unduh Gratis Kutools untuk Excel Sekarang! )

1. Aktifkan buku kerja yang ingin Anda pisahkan menjadi beberapa file teks.

2. Klik Enterprise > Buku catatan > Pisahkan Buku Kerja, lihat tangkapan layar:

3. di Pisahkan Buku Kerja kotak dialog:

(1.) Periksa lembar kerja yang ingin Anda pisahkan.

(2.) Periksa Tentukan format penyimpanan, lalu pilih format file yang ingin Anda simpan, misalnya Anda dapat memilih txt, csv, pdf, xlsx or xls format file yang Anda butuhkan.

(3.) Kemudian klik Split tombol, di kotak prompt berikut tentukan folder untuk mengeluarkan file terpisah.

excel add-in split kotak dialog buku kerja 2 excel add-in pilih lokasi

4. Lalu klik OK tombol, dan lembar kerja yang Anda pilih akan dibagi dan disimpan ke folder yang Anda inginkan dengan format yang Anda butuhkan.

excel add-in file terpisah

Unduh Gratis Kutools untuk Excel Sekarang!

Alat Produktivitas Kantor Terbaik

馃 Kutools AI Ajudan: Merevolusi analisis data berdasarkan: Eksekusi Cerdas   |  Hasilkan Kode  |  Buat Rumus Khusus  |  Analisis Data dan Hasilkan Grafik  |  Aktifkan Fungsi Kutools...
Fitur Populer: Temukan, Sorot, atau Identifikasi Duplikat   |  Hapus Baris Kosong   |  Gabungkan Kolom atau Sel tanpa Kehilangan Data   |   Putaran tanpa Formula ...
Pencarian Super: VLookup Beberapa Kriteria    VLookup Nilai Berganda  |   VLookup di Beberapa Lembar   |   Pencarian Fuzzy ....
Daftar Drop-down Lanjutan: Buat Daftar Drop Down dengan Cepat   |  Daftar Drop Down yang Bergantung   |  Multi-pilih Drop Down List ....
Manajer Kolom: Tambahkan Jumlah Kolom Tertentu  |  Pindahkan Kolom  |  Alihkan Status Visibilitas Kolom Tersembunyi  |  Bandingkan Rentang & Kolom ...
Fitur Unggulan: Fokus Kisi   |  Tampilan Desain   |   Bar Formula Besar    Manajer Buku Kerja & Lembar   |  Perpustakaan Sumberdaya (Teks otomatis)   |  Pemetik tanggal   |  Gabungkan Lembar Kerja   |  Enkripsi/Dekripsi Sel    Kirim Email berdasarkan Daftar   |  Filter Super   |   Filter Khusus (filter tebal/miring/coret...) ...
15 Perangkat Teratas12 Teks Tools (Tambahkan Teks, Hapus Karakter, ...)   |   50 + Grafik jenis (Gantt Chart, ...)   |   40+ Praktis Rumus (Hitung usia berdasarkan ulang tahun, ...)   |   19 Insersi Tools (Masukkan Kode QR, Sisipkan Gambar dari Jalur, ...)   |   12 Konversi Tools (Angka ke Kata, Konversi Mata Uang, ...)   |   7 Gabungkan & Pisahkan Tools (Lanjutan Gabungkan Baris, Pisahkan Sel, ...)   |   ... dan banyak lagi

Tingkatkan Keterampilan Excel Anda dengan Kutools for Excel, dan Rasakan Efisiensi yang Belum Pernah Ada Sebelumnya. Kutools for Excel Menawarkan Lebih dari 300 Fitur Lanjutan untuk Meningkatkan Produktivitas dan Menghemat Waktu.  Klik Di Sini untuk Mendapatkan Fitur yang Paling Anda Butuhkan...

Deskripsi Produk


Tab Office Membawa antarmuka Tab ke Office, dan Membuat Pekerjaan Anda Jauh Lebih Mudah

  • Aktifkan pengeditan dan pembacaan tab di Word, Excel, PowerPoint, Publisher, Access, Visio, dan Project.
  • Buka dan buat banyak dokumen di tab baru di jendela yang sama, bukan di jendela baru.
  • Meningkatkan produktivitas Anda sebesar 50%, dan mengurangi ratusan klik mouse untuk Anda setiap hari!
Comments (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I had tried with a txt file where there were multiple tables with numbers saved with commas but the program did not recognize the comma as a decimal point. How can I fix this error?
This comment was minimized by the moderator on the site
What would I need to change in the code to make it not open them in a new workbook?
This comment was minimized by the moderator on the site
This code helped me exactly to solve my issue, thanks for the code.
This comment was minimized by the moderator on the site
thank you , multiple text files to different worksheets code worked!
This comment was minimized by the moderator on the site
Thanks for this code this is working great.. i want to merge all the selected sheet into a single sheet is that possible..
This comment was minimized by the moderator on the site
How do I change this macros to display text file saved as UTF-8 or in other words using Platform = 65001, Thanks
This comment was minimized by the moderator on the site
Thanks for this very useful code. I have a question though. What I can change to convert the datatype from General to Text as currently it only imports data into General format.
This comment was minimized by the moderator on the site
Is it possible to open Sequencially multiple txt files in a single sheet ?
This comment was minimized by the moderator on the site
The code for "Import multiple text files to separate worksheets with VBA code" works for me, BUT cuts off the data of each cell at 255 characters. I think it is defaulting to GeneralFormat cell data, but I need it to be TextFormat. Unfortunately I cannot figure out how to adjust the code to fix this.
This comment was minimized by the moderator on the site
I used Following code But Space Didn't Delimit. Turned Tab:=True, Space:=True, but it didn't work. My Txt file format is- ALUMINI16MAYFUT 09-05-2016 10:00:00 106.0000 106.0000 105.2000 105.3500 104 Any Solution?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations