ไปยังเนื้อหาหลัก

วิธีการส่งออกข้อมูล Excel (การเลือกหรือแผ่นงาน) ไปยังไฟล์ข้อความใน Excel

หากคุณจำเป็นต้องส่งสมุดงานในรูปแบบของไฟล์ข้อความคุณต้องแปลงสมุดงานเป็นไฟล์ข้อความ และบทความนี้จะแนะนำวิธีการสองวิธีในการส่งออกข้อมูล Excel เป็นไฟล์ข้อความได้อย่างง่ายดาย

ส่งออกแผ่นเดียวไปยังไฟล์ข้อความใน Excel

ตามค่าเริ่มต้นข้อมูล Excel จะถูกบันทึกเป็นสมุดงานในรูปแบบของ .xlsx. อย่างไรก็ตามเราสามารถส่งออกแผ่นงานของสมุดงานที่มีอยู่เป็นไฟล์ข้อความด้วยไฟล์ บันทึกเป็น ลักษณะเฉพาะ. โปรดดำเนินการดังนี้:

1. เลื่อนไปที่แผ่นงานที่คุณจะส่งออกเป็นไฟล์ข้อความแล้วคลิก เนื้อไม่มีมัน (หรือ ปุ่ม Office)> บันทึกเป็น.

2. ในการเปิด บันทึกเป็น กล่องโต้ตอบเลือกโฟลเดอร์ปลายทางที่คุณจะบันทึกไฟล์ข้อความที่ส่งออกตั้งชื่อไฟล์ในไฟล์ ชื่อไฟล์ จากนั้นเลือกไฟล์ ข้อความ Unicode (* .txt) จากไฟล์ บันทึกเป็นชนิด รายการแบบเลื่อนลง ดูภาพหน้าจอ:
ส่งออกเป็นไฟล์ข้อความด้วยคุณสมบัติบันทึกเป็น

3. จากนั้นจะปรากฏขึ้นสองกล่องโต้ตอบคำเตือนเพื่อขอให้คุณส่งออกเฉพาะแผ่นงานที่ใช้งานอยู่เป็นไฟล์ข้อความและทิ้งคุณสมบัติที่เข้ากันไม่ได้กับไฟล์ข้อความ คลิก OK ปุ่มและ ใช่ ปุ่มต่อเนื่อง

จากนั้นข้อมูลในแผ่นงานที่ใช้งานอยู่จะถูกส่งออกเป็นไฟล์ข้อความใหม่

หมายเหตุ: บันทึกเป็น คำสั่งสามารถส่งออกข้อมูลของแผ่นงานที่ใช้งานเป็นไฟล์ข้อความเท่านั้น หากคุณต้องการส่งออกข้อมูลทั้งหมดของสมุดงานทั้งหมดคุณต้องบันทึกแต่ละแผ่นงานเป็นไฟล์ข้อความทีละไฟล์


ส่งออกสิ่งที่เลือก (หรือหนึ่งคอลัมน์) ไปยังไฟล์ข้อความด้วย VBA

รหัส VBA ต่อไปนี้ยังช่วยให้คุณสามารถส่งออกข้อมูลช่วงที่เลือก (เช่นคอลัมน์เดียว) ไปยังไฟล์ข้อความได้โปรดดำเนินการดังนี้:

1. ค้างไว้ ALT + F11 และจะเปิดไฟล์ Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

2. คลิก สิ่งที่ใส่เข้าไป > โมดูลและวางรหัสต่อไปนี้ในหน้าต่างโมดูล

VBA: ส่งออกการเลือกหรือแผ่นงานทั้งหมดไปยังไฟล์ข้อความ

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. จากนั้นกด F5 กุญแจสำคัญในการเรียกใช้รหัสนี้ จากนั้นเลือกช่วงข้อมูลที่คุณต้องการส่งออกในกล่องโต้ตอบป๊อปอัปแล้วคลิกไฟล์ OK ปุ่มดูภาพหน้าจอ:
เลือกหนึ่งคอลัมน์เพื่อส่งออกเป็นไฟล์ข้อความ

4. และตอนนี้ในกล่องโต้ตอบบันทึกเป็นอื่นโปรดระบุชื่อสำหรับไฟล์ข้อความนี้และโฟลเดอร์ที่จะใส่ไฟล์นี้แล้วคลิก ลด ปุ่ม


ส่งออกสิ่งที่เลือก (หรือหนึ่งคอลัมน์) ไปยังไฟล์ข้อความด้วย Kutools for Excel

พื้นที่ บันทึกเป็น คำสั่งสามารถส่งออกข้อมูลทั้งหมดในแผ่นงานที่ใช้งานเป็นข้อความ จะเกิดอะไรขึ้นหากส่งออกข้อมูลทั้งหมดของแผ่นงานที่ไม่ได้ใช้งานที่ระบุหรือบางส่วนของข้อมูลในแผ่นงานเป็นไฟล์ข้อความ Kutools สำหรับ Excel's ส่งออกช่วงไปยังไฟล์ ยูทิลิตี้สามารถช่วยเราส่งออกและบันทึกข้อมูลในการเลือกเป็นไฟล์ข้อความได้อย่างง่ายดาย ..  

Kutools สำหรับ Excel - เต็มไปด้วยเครื่องมือที่จำเป็นสำหรับ Excel มากกว่า 300 รายการ เพลิดเพลินกับฟีเจอร์ทดลองใช้ฟรี 30 วันโดยไม่ต้องใช้บัตรเครดิต! ดาวน์โหลดเดี๋ยวนี้!

1. เลือกรังที่คุณจะส่งออกไปยังไฟล์ข้อความ (ในกรณีของเราเราเลือกคอลัมน์ A) แล้วคลิก Kutools พลัส > นำเข้าส่งออก > ส่งออกช่วงไปยังไฟล์ดูภาพหน้าจอ:
Addin ของ Excel: ส่งออกสิ่งที่เลือกไปยังไฟล์ข้อความ

2. ตัว Vortex Indicator ได้ถูกนำเสนอลงในนิตยสาร ส่งออกช่วงไปยังไฟล์ กล่องโต้ตอบทำตามภาพด้านล่างที่แสดง:
Addin ของ Excel: ส่งออกสิ่งที่เลือกไปยังไฟล์ข้อความ
(1) ตรวจสอบไฟล์ ข้อความ Unicode ตัวเลือกใน รูปแบบไฟล์ มาตรา;
(2) ตรวจสอบตัวเลือกบันทึกค่าจริงหรือบันทึกค่าตามที่แสดงบนหน้าจอตัวเลือกตามที่คุณต้องการในส่วนตัวเลือกข้อความ
(3) ระบุโฟลเดอร์ปลายทางที่คุณจะบันทึกไฟล์ข้อความที่ส่งออกไป
(4) คลิกไฟล์ Ok ปุ่ม

3. ตั้งชื่อไฟล์ข้อความที่ส่งออกในกล่องโต้ตอบการเปิดใหม่แล้วคลิกไฟล์ Ok ปุ่ม
ตั้งชื่อไฟล์ข้อความที่ส่งออก

จากนั้นการเลือก (คอลัมน์ A ที่เลือก) จะถูกส่งออกเป็นไฟล์ข้อความและบันทึกลงในโฟลเดอร์ที่ระบุ

Kutools สำหรับ Excel - เพิ่มประสิทธิภาพ Excel ด้วยเครื่องมือที่จำเป็นมากกว่า 300 รายการ เพลิดเพลินกับฟีเจอร์ทดลองใช้ฟรี 30 วันโดยไม่ต้องใช้บัตรเครดิต! Get It Now


ส่งออกแผ่นงานหลายแผ่นเพื่อแยกไฟล์ข้อความใน Excel

บางครั้งคุณอาจต้องส่งออกแผ่นงานหลายแผ่นไปยังไฟล์ข้อความหลายไฟล์ใน Excel คุณลักษณะบันทึกเป็นอาจน่าเบื่อเล็กน้อย! ไม่ต้องกังวล! Kutools สำหรับ Excel's แยกสมุดงาน ยูทิลิตี้ช่วยให้ผู้ใช้ Excel สามารถแก้ไขปัญหาได้อย่างง่ายดายในการส่งออกแผ่นงานหลายแผ่นไปยังไฟล์ข้อความแยกกันหลาย ๆ 

Kutools สำหรับ Excel - เต็มไปด้วยเครื่องมือที่จำเป็นสำหรับ Excel มากกว่า 300 รายการ เพลิดเพลินกับฟีเจอร์ทดลองใช้ฟรี 30 วันโดยไม่ต้องใช้บัตรเครดิต! ดาวน์โหลดเดี๋ยวนี้!

1 คลิก Kutools พลัส > สมุดงานแยกสมุดงาน. ดูภาพหน้าจอ:
Addin ของ Excel: ส่งออกหลายแผ่นไปยังไฟล์ข้อความ

2. ในกล่องโต้ตอบแยกสมุดงานเปิดโปรดทำดังนี้:
Addin ของ Excel: ส่งออกหลายแผ่นไปยังไฟล์ข้อความ
(1) ตรวจสอบแผ่นงานที่คุณจะส่งออกไปยังไฟล์ข้อความแยกต่างหากในไฟล์ ชื่อสมุดงาน มาตรา;
(2) ตรวจสอบไฟล์ ระบุรูปแบบการบันทึก จากนั้นเลือกตัวเลือก ข้อความ Unicode (* .txt) จากรายการแบบเลื่อนลงด้านล่างดูภาพหน้าจอด้านซ้าย:
(3) คลิกไฟล์ แยก ปุ่ม

3. จากนั้นในกล่องโต้ตอบเรียกดูโฟลเดอร์ที่เปิดขึ้นมาให้เลือกโฟลเดอร์ปลายทางที่คุณจะบันทึกไฟล์ข้อความที่ส่งออกแล้วคลิก OK ปุ่ม

จนถึงขณะนี้แผ่นงานที่ระบุแต่ละแผ่นได้ถูกส่งออกเป็นไฟล์ข้อความแยกกันและบันทึกลงในโฟลเดอร์ที่ระบุ

Kutools สำหรับ Excel - เพิ่มประสิทธิภาพ Excel ด้วยเครื่องมือที่จำเป็นมากกว่า 300 รายการ เพลิดเพลินกับฟีเจอร์ทดลองใช้ฟรี 30 วันโดยไม่ต้องใช้บัตรเครดิต! Get It Now

บันทึกแต่ละแผ่นเป็นไฟล์ PDF / text / csv หรือสมุดงานแยกกันใน Excel ได้อย่างง่ายดาย

โดยปกติเราสามารถบันทึกแผ่นงานที่ใช้งานอยู่เป็นไฟล์. pdf, ไฟล์. txt หรือไฟล์. csv โดยใช้คุณลักษณะบันทึกเป็น แต่ Kutools สำหรับ Excel's แยกสมุดงาน ยูทิลิตี้สามารถช่วยให้คุณบันทึกแต่ละสมุดงานเป็นไฟล์ PDF / TEXT / CSV หรือสมุดงานใน Excel แยกกันได้อย่างง่ายดาย


สมุดงานแยกโฆษณา pdf 1

Kutools สำหรับ Excel - เพิ่มประสิทธิภาพ Excel ด้วยเครื่องมือที่จำเป็นมากกว่า 300 รายการ เพลิดเพลินกับฟีเจอร์ทดลองใช้ฟรี 30 วันโดยไม่ต้องใช้บัตรเครดิต! Get It Now


การสาธิต: ส่งออกข้อมูล Excel (การเลือกหรือแผ่นงาน) ไปยังไฟล์ข้อความใน Excel


Kutools สำหรับ Excel: เครื่องมือแสนสะดวกกว่า 300 รายการอยู่แค่เพียงปลายนิ้วสัมผัส! เริ่มทดลองใช้ฟรี 30 วันโดยไม่มีข้อจำกัดด้านฟีเจอร์ตั้งแต่วันนี้ Download Now!

บทความที่เกี่ยวข้อง:

สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

🤖 Kutools AI ผู้ช่วย: ปฏิวัติการวิเคราะห์ข้อมูลโดยยึดตาม: การดำเนินการที่ชาญฉลาด   |  สร้างรหัส  |  สร้างสูตรที่กำหนดเอง  |  วิเคราะห์ข้อมูลและสร้างแผนภูมิ  |  เรียกใช้ฟังก์ชัน Kutools...
คุณสมบัติยอดนิยม: ค้นหา เน้น หรือระบุรายการที่ซ้ำกัน   |  ลบแถวว่าง   |  รวมคอลัมน์หรือเซลล์โดยไม่สูญเสียข้อมูล   |   รอบโดยไม่มีสูตร ...
การค้นหาขั้นสูง: VLookup หลายเกณฑ์    VLookup หลายค่า  |   VLookup ข้ามหลายแผ่น   |   การค้นหาที่ไม่ชัดเจน ....
รายการแบบเลื่อนลงขั้นสูง: สร้างรายการแบบหล่นลงอย่างรวดเร็ว   |  รายการแบบหล่นลงขึ้นอยู่กับ   |  เลือกหลายรายการแบบหล่นลง ....
ผู้จัดการคอลัมน์: เพิ่มจำนวนคอลัมน์เฉพาะ  |  ย้ายคอลัมน์  |  สลับสถานะการมองเห็นของคอลัมน์ที่ซ่อนอยู่  |  เปรียบเทียบช่วงและคอลัมน์ ...
คุณสมบัติเด่น: กริดโฟกัส   |  มุมมองการออกแบบ   |   บาร์สูตรใหญ่    สมุดงานและตัวจัดการชีต   |  ห้องสมุดทรัพยากร (ข้อความอัตโนมัติ)   |  เลือกวันที่   |  รวมแผ่นงาน   |  เข้ารหัส/ถอดรหัสเซลล์    ส่งอีเมลตามรายการ   |  ซุปเปอร์ฟิลเตอร์   |   ตัวกรองพิเศษ (กรองตัวหนา/ตัวเอียง/ขีดทับ...) ...
ชุดเครื่องมือ 15 อันดับแรก12 ข้อความ เครื่องมือ (เพิ่มข้อความ, ลบอักขระ, ... )   |   50 + แผนภูมิ ประเภท (แผนภูมิ Gantt, ... )   |   40+ ใช้งานได้จริง สูตร (คำนวณอายุตามวันเกิด, ... )   |   19 การแทรก เครื่องมือ (ใส่ QR Code, แทรกรูปภาพจากเส้นทาง, ... )   |   12 การแปลง เครื่องมือ (ตัวเลขเป็นคำ, การแปลงสกุลเงิน, ... )   |   7 ผสานและแยก เครื่องมือ (แถวรวมขั้นสูง, แยกเซลล์, ... )   |   ... และอื่น ๆ

เพิ่มพูนทักษะ Excel ของคุณด้วย Kutools สำหรับ Excel และสัมผัสประสิทธิภาพอย่างที่ไม่เคยมีมาก่อน Kutools สำหรับ Excel เสนอคุณสมบัติขั้นสูงมากกว่า 300 รายการเพื่อเพิ่มประสิทธิภาพและประหยัดเวลา  คลิกที่นี่เพื่อรับคุณสมบัติที่คุณต้องการมากที่สุด...

รายละเอียด


แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก

  • เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, Visio และโครงการ
  • เปิดและสร้างเอกสารหลายรายการในแท็บใหม่ของหน้าต่างเดียวกันแทนที่จะเป็นในหน้าต่างใหม่
  • เพิ่มประสิทธิภาพการทำงานของคุณ 50% และลดการคลิกเมาส์หลายร้อยครั้งให้คุณทุกวัน!
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