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

วิธีรวมสมุดงานหลายเล่มไว้ในสมุดงานหลักใน Excel

คุณเคยติดขัดเมื่อต้องรวมสมุดงานหลายเล่มไว้ในสมุดงานหลักใน Excel หรือไม่? สิ่งที่น่ากลัวที่สุดคือสมุดงานที่คุณต้องรวมมีหลายแผ่นงาน และจะรวมเฉพาะแผ่นงานที่ระบุของสมุดงานหลายเล่มเป็นสมุดงานเดียวได้อย่างไร? บทช่วยสอนนี้สาธิตวิธีการที่มีประโยชน์หลายอย่างเพื่อช่วยคุณแก้ปัญหาทีละขั้นตอน


รวมสมุดงานหลายเล่มไว้ในสมุดงานเดียวด้วยฟังก์ชันย้ายหรือคัดลอก

หากจำเป็นต้องรวมสมุดงานเพียงไม่กี่เล่มคุณสามารถใช้คำสั่งย้ายหรือคัดลอกเพื่อย้ายหรือคัดลอกแผ่นงานจากสมุดงานต้นฉบับไปยังสมุดงานหลักด้วยตนเอง

1. เปิดสมุดงานที่คุณจะรวมเข้ากับสมุดงานหลัก

2. เลือกแผ่นงานในสมุดงานต้นฉบับที่คุณจะย้ายหรือคัดลอกไปยังสมุดงานหลัก

หมายเหตุ:

1). คุณสามารถเลือกแผ่นงานที่ไม่อยู่ติดกันได้หลายแผ่นโดยถือไฟล์ Ctrl คีย์และคลิกแท็บแผ่นงานทีละรายการ

2). สำหรับการเลือกแผ่นงานที่อยู่ติดกันหลายแผ่นโปรดคลิกที่แท็บแผ่นงานแรกค้างไว้ เปลี่ยน จากนั้นคลิกแท็บแผ่นงานสุดท้ายเพื่อเลือกทั้งหมด

3). คุณสามารถคลิกขวาที่แท็บแผ่นงานใดก็ได้คลิกที่ เลือกแผ่นงานทั้งหมด จากเมนูบริบทเพื่อเลือกแผ่นงานทั้งหมดในสมุดงานพร้อมกัน

3. หลังจากเลือกแผ่นงานที่ต้องการแล้วให้คลิกขวาที่แท็บแผ่นงานจากนั้นคลิก ย้ายหรือคัดลอก จากเมนูบริบท ดูภาพหน้าจอ:

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

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


รวมสมุดงานหลายเล่มหรือแผ่นงานที่ระบุเข้ากับสมุดงานหลักด้วย VBA

หากจำเป็นต้องรวมสมุดงานหลายเล่มเข้าด้วยกันคุณสามารถใช้รหัส VBA ต่อไปนี้เพื่อใช้งานได้อย่างรวดเร็ว กรุณาดำเนินการดังนี้

1. ใส่สมุดงานทั้งหมดที่คุณต้องการรวมไว้ในไดเร็กทอรีเดียวกัน

2. เปิดไฟล์ Excel (สมุดงานนี้จะเป็นสมุดงานหลัก)

3 กด อื่น ๆ + F11 คีย์เพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง. ใน Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่างคลิก สิ่งที่ใส่เข้าไป > โมดูลจากนั้นคัดลอกโค้ด VBA ด้านล่างลงในหน้าต่างโมดูล

รหัส VBA 1: รวมสมุดงาน Excel หลายเล่มเข้าด้วยกัน

Sub GetSheets()
'Updated by Extendoffice 2019/2/20
Path = "C:\Users\dt\Desktop\dt kte\"
Filename = Dir(Path & "*.xlsx")
  Do While Filename <> ""
  Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
     For Each Sheet In ActiveWorkbook.Sheets
     Sheet.Copy After:=ThisWorkbook.Sheets(1)
  Next Sheet
     Workbooks(Filename).Close
     Filename = Dir()
  Loop
End Sub
	

หมายเหตุ:

1. รหัส VBA ด้านบนจะเก็บชื่อแผ่นงานของสมุดงานต้นฉบับไว้หลังจากรวมเข้าด้วยกัน

2. หากคุณต้องการแยกว่าแผ่นงานใดในสมุดงานหลักมาจากที่ใดหลังจากการรวมโปรดใช้รหัส VBA ด้านล่าง 2

3. หากคุณต้องการรวมแผ่นงานที่ระบุไว้ในสมุดงานหลักรหัส VBA 3 ด้านล่างสามารถช่วยได้

ในรหัส VBA“C: \ Users \ DT168 \ Desktop \ KTE \” คือเส้นทางโฟลเดอร์ ในรหัส VBA 3 "Sheet1, Sheet3"คือแผ่นงานที่ระบุของสมุดงานที่คุณจะรวมเข้ากับสมุดงานหลักคุณสามารถเปลี่ยนได้ตามความต้องการของคุณ

รหัส VBA 2: รวมสมุดงานเป็นหนึ่ง (แต่ละแผ่นงานจะได้รับการตั้งชื่อด้วยคำนำหน้าชื่อไฟล์เดิม):

Sub MergeWorkbooks()
'Updated by Extendoffice 2019/2/20
Dim xStrPath As String
Dim xStrFName As String
Dim xWS As Worksheet
Dim xMWS As Worksheet
Dim xTWB As Workbook
Dim xStrAWBName As String
On Error Resume Next
xStrPath = "C:\Users\DT168\Desktop\KTE\"
xStrFName = Dir(xStrPath & "*.xlsx")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set xTWB = ThisWorkbook
Do While Len(xStrFName) > 0
    Workbooks.Open Filename:=xStrPath & xStrFName, ReadOnly:=True
    xStrAWBName = ActiveWorkbook.Name
    For Each xWS In ActiveWorkbook.Sheets
    xWS.Copy After:=xTWB.Sheets(xTWB.Sheets.Count)
    Set xMWS = xTWB.Sheets(xTWB.Sheets.Count)
    xMWS.Name = xStrAWBName & "(" & xMWS.Name & ")"
    Next xWS
    Workbooks(xStrAWBName).Close
    xStrFName = Dir()
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

รหัส VBA 3: ผสานเวิร์กชีทที่ระบุไว้ในสมุดงานหลัก:

Sub MergeSheets2()
'Updated by Extendoffice 2019/2/20
Dim xStrPath As String
Dim xStrFName As String
Dim xWS As Worksheet
Dim xMWS As Worksheet
Dim xTWB As Workbook
Dim xStrAWBName As String
Dim xI As Integer
On Error Resume Next

xStrPath = " C:\Users\DT168\Desktop\KTE\"
xStrName = "Sheet1,Sheet3"

xArr = Split(xStrName, ",")

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set xTWB = ThisWorkbook
xStrFName = Dir(xStrPath & "*.xlsx")
Do While Len(xStrFName) > 0
Workbooks.Open Filename:=xStrPath & xStrFName, ReadOnly:=True
xStrAWBName = ActiveWorkbook.Name
For Each xWS In ActiveWorkbook.Sheets
For xI = 0 To UBound(xArr)
If xWS.Name = xArr(xI) Then
xWS.Copy After:=xTWB.Sheets(xTWB.Sheets.count)
Set xMWS = xTWB.Sheets(xTWB.Sheets.count)
xMWS.Name = xStrAWBName & "(" & xArr(xI) & ")"
Exit For
End If
Next xI
Next xWS
Workbooks(xStrAWBName).Close
xStrFName = Dir()
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

4 กด F5 กุญแจสำคัญในการเรียกใช้รหัส จากนั้นแผ่นงานทั้งหมดหรือแผ่นงานที่ระบุของสมุดงานในโฟลเดอร์นั้นจะรวมเข้ากับสมุดงานหลักพร้อมกัน


รวมสมุดงานหลายชุดหรือแผ่นงานที่ระบุไว้ในสมุดงานเดียวได้อย่างง่ายดาย

โชคดีที่ รวมกัน ยูทิลิตี้สมุดงานของ Kutools สำหรับ Excel ทำให้ง่ายขึ้นมากในการรวมสมุดงานหลายเล่มเป็นหนึ่งเดียว มาดูวิธีทำให้ฟังก์ชันนี้ทำงานในการรวมสมุดงานหลายชุด

ก่อนที่จะใช้ Kutools สำหรับ Excelโปรด ดาวน์โหลดและติดตั้งในตอนแรก.

1. สร้างสมุดงานใหม่แล้วคลิก Kutools พลัส > รวมกัน. จากนั้นกล่องโต้ตอบจะปรากฏขึ้นเพื่อเตือนคุณว่าควรบันทึกเวิร์กบุ๊กรวมทั้งหมดและไม่สามารถใช้คุณลักษณะนี้กับเวิร์กบุ๊กที่มีการป้องกันได้โปรดคลิกที่ OK ปุ่ม

2 ใน รวมแผ่นงาน ตัวช่วยสร้างเลือก รวมแผ่นงานหลายแผ่นจากสมุดงานไว้ในสมุดงานเดียว จากนั้นคลิกตัวเลือก ถัดไป ปุ่ม. ดูภาพหน้าจอ:

3 ใน รวมแผ่นงาน - ขั้นตอนที่ 2 จาก 3 ใหคลิกปุ the ม เพิ่ม > เนื้อไม่มีมัน or โฟลเดอร์ เพื่อเพิ่มไฟล์ Excel คุณจะรวมเป็นไฟล์เดียว หลังจากเพิ่มไฟล์ Excel แล้วให้คลิกไฟล์ เสร็จสิ้น และเลือกโฟลเดอร์เพื่อบันทึกสมุดงานหลัก ดูภาพหน้าจอ:

ตอนนี้สมุดงานทั้งหมดรวมเป็นหนึ่งเดียว

เมื่อเทียบกับสองวิธีข้างต้น Kutools สำหรับ Excel มีข้อดีดังต่อไปนี้:

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

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


Kutools สำหรับ Excel - ช่วยให้คุณทำงานเสร็จก่อนเวลาเสมอมีเวลาสนุกกับชีวิตมากขึ้น
คุณมักพบว่าตัวเองมัว แต่เล่นงานไม่มีเวลาทำเพื่อตัวเองและครอบครัว?  Kutools สำหรับ Excel สามารถช่วยให้คุณจัดการกับ 80% ไขปริศนา Excel และปรับปรุงประสิทธิภาพการทำงาน 80% ให้คุณมีเวลาดูแลครอบครัวและสนุกกับชีวิตมากขึ้น
300 เครื่องมือขั้นสูงสำหรับ 1500 สถานการณ์การทำงาน ทำให้งานของคุณง่ายขึ้นกว่าที่เคย
ไม่จำเป็นต้องจำสูตรและรหัส VBA อีกต่อไปให้สมองของคุณได้พักผ่อนตั้งแต่บัดนี้เป็นต้นไป
การดำเนินการที่ซับซ้อนและซ้ำ ๆ สามารถดำเนินการครั้งเดียวในไม่กี่วินาที
ลดการใช้งานคีย์บอร์ดและเมาส์นับพันทุกวันบอกลาโรคจากการทำงานได้เลย
เป็นผู้เชี่ยวชาญด้าน Excel ใน 3 นาทีช่วยให้คุณได้รับการยอมรับอย่างรวดเร็วและโปรโมชั่นเพิ่มเงิน
110,000 คนที่มีประสิทธิภาพสูงและทางเลือกของ บริษัท ที่มีชื่อเสียงระดับโลกกว่า 300 บริษัท
ทำให้ $ 39.0 ของคุณคุ้มค่ากว่า $ 4000.0 การฝึกอบรมของผู้อื่น
ทดลองใช้ฟีเจอร์เต็มรูปแบบฟรี 30 วัน รับประกันคืนเงินภายใน 60 วันโดยไม่มีเหตุผล

Comments (146)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I have one workbook with 100+ sheets, I want to move all 100+ sheets into another workbook in a single sheet.
This comment was minimized by the moderator on the site
I had to read throught the comments to find suggestions that worked for my application of the VBA CODE 2, but I managed to get it to work doing the following things:
1. make sure to change "C:\Users\DT168\Desktop\KTE\" to your own directory to wherever you have your files are located. don't forget the extra "\" at the end!2. my spreadsheets were extension ".xls", so I deleted the extra "x" in this line, like so: xStrFName = Dir(xStrPath & "*.xlsx")3. I placed all my spreadsheets in a single folder, and only those files were the contents of that folder, the target macro enabled spreadsheet where this vba was running from was saved outside of this folder (hopefully this makes sense).
one thing that I didn't want to mess with though is I only needed to merge the 1st tab of each spreadsheet, but I didn't want to mess with the code so if each workbook you want to merge into one has multiple tabs, this code will grab all of the tabs on each workbook and place them in your target spreadsheet, I had to manually delete all the tabs I didn't want.
if the author of this vba could reply to me, how do you change the code to just copy the 1st tab as opposed to all the tabs?
thank you!
This comment was minimized by the moderator on the site
hi I want a change. If the the sheet name is same then the data should be appended in the same name sheet rather than adding a sheet. for example if i have 10 files with jan, feb, mar same sheetnames. then result should be 1 file having jan, feb, mar only 3 sheets with the data of all 10 files. thanks
This comment was minimized by the moderator on the site
Good morning,

Basically I have to copy the values of another file example c: \ test.xlsx (sheet name "date"):

I have to copy the values from A2: T20


And I have to paste in another Extract.xlsx file on the “Extracts” folder on A2.


PLEASE NOTE: You must run vba when opening the file.
This comment was minimized by the moderator on the site
Hello! I need to merge multiple files into one, that are password protected. All source files use the same password. What changes are needed to the first VBA script to merge the files without having to enter the password each time?
This comment was minimized by the moderator on the site
Hello any one can help me, I want to combine sheet 2 only from 5 different sheet, can you script for me.
This comment was minimized by the moderator on the site
you can use Array function to copy the multiple sheets to combine in one file
Sheets(Array("Sheet1","Sheet2")).copy
This comment was minimized by the moderator on the site
hai sir i want know code for copying multiple sheets in one excel to multiple excels
This comment was minimized by the moderator on the site
Sheets(Array("Sheet1","Sheet2")).copy
This comment was minimized by the moderator on the site
hai sir i want know code for copying multiple sheets in one excel to multiple excels
This comment was minimized by the moderator on the site
how to use VBA code 1 to amend and make it runs to combine all the .xlsx files into one excel file and each excel spreedsheet tab in the combined excel file should be named as original file name.thanks
This comment was minimized by the moderator on the site
What part of VBA code 3 specifies the name of the worksheet to be copied?
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