Loncat ke daftar isi utama

Bagaimana cara mengekspor data Excel (seleksi atau lembaran) ke file teks di Excel?

Jika Anda diminta untuk mengirimkan buku kerja dalam format file teks, Anda perlu mengonversi buku kerja tersebut menjadi file teks. Dan artikel ini akan memperkenalkan Anda dua metode untuk mengekspor data Excel menjadi file teks dengan mudah.

Ekspor satu lembar ke file teks di Excel

Secara default, data Excel akan disimpan sebagai buku kerja dalam format . Xlsx. Namun, kami dapat mengekspor lembar kerja dari buku kerja yang ada sebagai file teks dengan Save As fitur. Harap lakukan sebagai berikut:

1. Geser ke lembar kerja yang akan Anda ekspor ke file teks, dan klik File (Atau Tombol kantor)> Save As.

2. Di pembukaan Save As kotak dialog, pilih folder tujuan tempat Anda akan menyimpan file teks yang diekspor, beri nama file di Nama file kotak, lalu pilih Teks Unicode (* .txt) dari Save as type daftar drop-down. Lihat tangkapan layar:
ekspor ke file teks dengan fitur Save As

3. Kemudian akan muncul dua kotak dialog peringatan yang meminta Anda untuk mengekspor hanya lembar kerja aktif sebagai file teks dan meninggalkan fitur yang tidak kompatibel dengan file teks. Klik OK Tombol dan Yes tombol berturut-turut.

Kemudian data di lembar kerja aktif diekspor sebagai file teks baru.

Note: Yang Save As Perintah hanya dapat mengekspor data lembar kerja aktif sebagai file teks. Jika Anda ingin mengekspor semua data dari seluruh buku kerja, Anda perlu menyimpan setiap lembar kerja sebagai file teks satu per satu.


Ekspor pilihan (atau satu kolom) ke file teks dengan VBA

Kode VBA berikut juga dapat membantu Anda mengekspor data rentang yang dipilih (misalnya satu kolom) ke file teks, lakukan seperti ini:

1. Tahan ALT + F11 kunci, dan itu membuka Microsoft Visual Basic untuk Aplikasi jendela.

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

VBA: pilihan ekspor atau seluruh lembar kerja ke file teks

Sub ExportRangetoFile()
'Update 20130913
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = Application.Workbooks.Add
WorkRng.Copy
wb.Worksheets(1).Paste
saveFile = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
wb.SaveAs Filename:=saveFile, FileFormat:=xlText, CreateBackup:=False
wb.Close
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

3. Lalu tekan F5 kunci untuk menjalankan kode ini. Dan kemudian pilih rentang data yang ingin Anda ekspor di kotak dialog yang muncul, dan klik OK tombol, lihat tangkapan layar:
Pilih satu kolom untuk mengekspor sebagai file teks

4. Dan sekarang di kotak dialog Save As lainnya, harap tentukan nama untuk file teks ini dan folder untuk meletakkan file ini, dan klik Save .


Ekspor pilihan (atau satu kolom) ke file teks dengan Kutools for Excel

Grafik Save As Perintah dapat mengekspor semua data di lembar kerja aktif sebagai teks. Bagaimana jika mengekspor semua data lembar kerja tidak aktif yang ditentukan, atau bagian dari data dalam lembar kerja sebagai file teks? Kutools untuk Excel's Ekspor Rentang ke File utilitas dapat membantu kami mengekspor dan menyimpan data yang dipilih sebagai file teks dengan mudah ..  

Kutools untuk Excel - Dilengkapi dengan lebih dari 300 alat penting untuk Excel. Nikmati uji coba GRATIS 30 hari berfitur lengkap tanpa memerlukan kartu kredit! Unduh sekarang!

1. Pilih rang yang akan Anda ekspor ke file teks (dalam kasus kami, kami memilih Kolom A), dan klik Kutools Ditambah > Ekspor Impor > Ekspor Rentang ke File, lihat tangkapan layar:
Addin Excel: mengekspor pilihan ke file teks

2. Dalam majalah Ekspor Rentang ke File kotak dialog, lakukan seperti gambar di bawah ini yang ditunjukkan:
Addin Excel: mengekspor pilihan ke file teks
(1) Periksa Teks Unicode pilihan dalam format file bagian;
(2) Centang opsi Simpan nilai aktual atau Simpan nilai seperti yang ditunjukkan di layar opsi yang Anda butuhkan di bagian Opsi teks;
(3) Tentukan folder tujuan tempat Anda akan menyimpan file teks yang diekspor;
(4) Klik Ok .

3. Beri nama file teks yang diekspor di kotak dialog pembukaan baru, dan klik Ok .
beri nama file teks yang diekspor

Dan kemudian pemilihan (Kolom A yang dipilih) telah diekspor sebagai file teks dan disimpan ke dalam folder yang ditentukan.

Kutools untuk Excel - Tingkatkan Excel dengan lebih dari 300 alat penting. Nikmati uji coba GRATIS 30 hari berfitur lengkap tanpa memerlukan kartu kredit! Get It Now


Ekspor beberapa lembar untuk memisahkan file teks di Excel

Terkadang Anda mungkin perlu mengekspor beberapa lembar kerja ke beberapa file teks di Excel. Fitur Simpan Sebagai mungkin sedikit membosankan! Jangan khawatir! Kutools untuk Excel Pisahkan Buku Kerja utilitas memberi pengguna Excel solusi mudah untuk mengekspor beberapa lembar kerja ke banyak file teks terpisah dengan beberapa klik. 

Kutools untuk Excel - Dilengkapi dengan lebih dari 300 alat penting untuk Excel. Nikmati uji coba GRATIS 30 hari berfitur lengkap tanpa memerlukan kartu kredit! Unduh sekarang!

1. klik Kutools Ditambah > Buku catatanPisahkan Buku Kerja. Lihat tangkapan layar:
Addin Excel: mengekspor beberapa lembar ke file teks

2. Di kotak dialog Split Workbook pembuka, lakukan hal berikut:
Addin Excel: mengekspor beberapa lembar ke file teks
(1) Periksa lembar kerja yang akan Anda ekspor ke file teks terpisah di Nama buku kerja bagian;
(2) Periksa Tentukan format penyimpanan opsi, lalu pilih Teks Unicode (* .txt) dari daftar drop-down di bawah, lihat tangkapan layar kiri:
(3) Klik Split .

3. Dan kemudian di kotak dialog Browse For Folder yang muncul, pilih folder tujuan tempat Anda akan menyimpan file teks yang diekspor, dan klik OK .

Sejauh ini setiap lembar kerja yang ditentukan telah diekspor sebagai file teks terpisah dan disimpan ke folder yang ditentukan.

Kutools untuk Excel - Tingkatkan Excel dengan lebih dari 300 alat penting. Nikmati uji coba GRATIS 30 hari berfitur lengkap tanpa memerlukan kartu kredit! Get It Now

Simpan secara massal setiap lembar sebagai file PDF / teks / csv terpisah atau buku kerja di Excel

Biasanya kita dapat menyimpan lembar kerja aktif sebagai file .pdf terpisah, file .txt, atau file .csv dengan fitur Save As. Tapi Kutools for Excel's Pisahkan Buku Kerja utilitas dapat membantu Anda dengan mudah menyimpan setiap buku kerja sebagai file PDF / TEXT / CSV terpisah atau buku kerja di Excel.


buku kerja pemisahan iklan pdf 1

Kutools untuk Excel - Tingkatkan Excel dengan lebih dari 300 alat penting. Nikmati uji coba GRATIS 30 hari berfitur lengkap tanpa memerlukan kartu kredit! Get It Now


Demo: ekspor data Excel (pilihan atau lembar) ke file Teks di Excel


Kutools untuk Excel: Lebih dari 300 alat praktis di ujung jari Anda! Mulai uji coba gratis 30 hari Anda tanpa batasan fitur hari ini. Download Sekarang!

Artikel Terkait:

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 (19)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
How would I amend the code for Export selection (or one column) to text file with VBA to autofill the filename with the contents of cell B2?
thanks
This comment was minimized by the moderator on the site
Hi,This is great, thanks a lot.
How would I alter the code for Export selection (or one column) to text file with VBA to auto fill the filename with the contents of cell B2?
This comment was minimized by the moderator on the site
Hi, this code is very useful for me. So thank you very much.
I want to ask that: When i'm using this code, a new line append automatically at the end of the txt content.
Can you help me about preventing this by vba?
This comment was minimized by the moderator on the site
hi guys, i used that code:
Sub ExportRangetoFile()
'Update 20130913
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = Application.Workbooks.Add
WorkRng.Copy
wb.Worksheets(1).Paste
saveFile = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
wb.SaveAs Filename:=saveFile, FileFormat:=xlText, CreateBackup:=False
wb.Close
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

and have working, but i need to savea column with cells that contain the function"concatenate", and when i play the vba code, and i save the .TXT file, only what appears it's #REF. how can i to fix it? cause i need the data that appears on that cells?
This comment was minimized by the moderator on the site
Has anyone been able to figure this out? I am having the same issue.
This comment was minimized by the moderator on the site
HELLO
THANK YOU FOR YOUR VBA CODE
SOMETIMES ON CERTAIN TEXT THERE IS "TEXT" IN EXPORT .TXT
THANK YOU FOR WHY
This comment was minimized by the moderator on the site
Thanks for the awesome piece of VBA code to export data to a text file. I have used your code with some of my own. The data I am dealing with is extremely line-length specific and after the macro has run, the text file contains some double quotation marks " at random places, which was never present in my data before. I have tried adding a code line to remove this character at various stages but that does not seem to be working. I am aware that I can manually remove this but would like to resolve it in the VBA code.

Sub Macro3()
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
Selection.AutoFilter
ActiveSheet.Range("$A$1:$B$10591").AutoFilter Field:=1, Criteria1:= _
"=NSZAP*", Operator:=xlAnd
Range("A1").Select
ActiveCell.Offset(200, 0).Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Rows("1:10101").EntireRow.Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.AutoFilter
Range(Selection, Selection.End(xlDown)).Select
Set WorkRng = Application.Selection
Set wb = Application.Workbooks.Add
WorkRng.Copy
wb.Worksheets(1).Paste
Selection.Replace What:="""", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
saveFile = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
Selection.Replace What:="""", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
wb.SaveAs Filename:=saveFile, FileFormat:=xlText, CreateBackup:=False
Selection.Replace What:="""", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
wb.Close
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hi Harish,
For removing a specified character in bulk, you can replace the character with nothing.
Ctrl + H to open the Find and Replace dialog box, type the specified character in the Find what box, and type noting in the replace with box.
This comment was minimized by the moderator on the site
3/2 You might also note that you don't need to specify the wb prefix once you've .Add ed the workbook since it becomes active. Specifying wb might or might not be more efficient but it can be omitted from some commands. Actually I entirely scrapped the variable wb; I just go Workbooks.Add, and use ActiveWorkbook when needed. (As you are suppressing ScreenUpdating it wouldn't be obvious to some that wb is Active. Tip for beginners (and higher): I always, always develop with ScreenUpdating and DisplayAlerts as True, and when done with development, I consider toggling them off for some passage of code.)
This comment was minimized by the moderator on the site
2/2 - vbYesNoCancel msgboxes and Booleans to indicate whether to export all, selection, or a user specified range - a static String for the prior range address - if len(that static)1 then I set WorkRng=activesheet.UsedRange (You can't copy multiple areas with a single copy, though with a little work you could walk the areas and copy them piecemeal.) - Idiotic Microsoft does not save off empty rows at the start and the bottom of the saved range, and does not save off empty columns at the leftmost and the rightmost of the saved range. When I detect that (UsedRange is not row 1, col. 1, or xlLastCell is not completely lower-right) I msgbox to ask user if they want to plug A1 or the lower right cell. - Then I decided to preemptively address the upper left issue by inserting a row and setting A1 to be text like "The following is for range " - I close with activeworkbook.close SaveChanges:=False - Long time habit since I'm an angry proponent of cleaning up (and the world is a sad place thanks to irresponsible programmers who shirk that responsibility when it matters), I set WorkRng = Nothing on the way out :)
This comment was minimized by the moderator on the site
1/2 (since your software limits comment length) I am a serious coder and I want to inform you that the VBA code here is outstanding. It's clean, and not one line too much, or one too few. It's exemplary coding for demonstration of the process. I'll also mention that as I extensively researched solutions for export of selection, you and only one other person suggested dropping the range into a temp new workbook. All other answers were painfully manually, walking through cell by cell. Even Chip's code is much longer and runs slower (but intentionally so, as it is much more flexible - specifiable delimiters, etc.) Just for your amusement, I made some very minor tweaks but otherwise nearly lifted the code word for word because it basically dropped right into a very intricate and specialized application. Some of these tweaks are something I'm sure you do in practice, but they add lines of code (e.g. error checking) so showing them on this webpage would have muddied your display so that the essential elements of processing would have been cumbersome for readers to follow along. Anyway: (see part 2)
This comment was minimized by the moderator on the site
My query is as mentioned below: I have a report to generate everyday. The data what I get on the final row (only one row but more than one columns) I want it to export to another excel sheet which is a summary excel sheet saved separately on my desktop. Eg: Day1 report - final row export to Summary excel sheet row1 Day2 report - final row export to Summary excel sheet row2 Day3 report - final row export to Summary excel sheet row3 and so on.. Export should be done through a click button., which means when I click on export button the data on the sheet I calculated today should go and save on the Summary excel sheet row1, next day a new excel sheet report calculated should go and save on the Summary excel sheet row2 and so on.. Will this be possible to do... If yes please someone help me on this... Thank you in advance...:-)
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