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

จะค้นหาและแทนที่ไฟล์หลาย ๆ ไฟล์ใน Word ได้อย่างไร?

หากคุณมีไฟล์คำหลายโหลที่มีเนื้อหาเดียวกัน (เช่นส่วนหัวส่วนท้ายคำหรือตัวเลขพิเศษบางคำ) และคุณจำเป็นต้องแทนที่เนื้อหาเดียวกันในเอกสารเหล่านั้นใน Word จะง่ายกว่าอย่างไรที่คุณจะทำมันให้เสร็จอย่างรวดเร็ว? แน่นอนคุณสามารถเปิดไฟล์เหล่านั้นทีละไฟล์เพื่อแทนที่เนื้อหาเดียวกันได้ แต่จะใช้เวลานานและยุ่งยาก บทช่วยสอนนี้จะแสดงวิธีที่ยุ่งยากในการแทนที่เนื้อหาเดียวกันภายในเอกสารหลายฉบับใน Word พร้อมกัน

ค้นหาและแทนที่ข้อความในเอกสารหลายคำพร้อมกันด้วยรหัส VBA
ค้นหาและแทนที่ข้อความที่แตกต่างกันในเอกสารหลายฉบับพร้อมกันได้อย่างง่ายดายด้วย Kutools for Word


ค้นหาและแทนที่ข้อความในเอกสารหลายคำพร้อมกันด้วยรหัส VBA

1 กด อื่น ๆ + F11 เพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

2 ใน Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่างคลิก สิ่งที่ใส่เข้าไปโมดูลจากนั้นคัดลอกรหัส VBA ต่อไปนี้ลงในหน้าต่างโมดูล

รหัส VBA: การค้นหาและแทนที่เนื้อหาเดียวกันในเอกสารหลายชุดพร้อมกัน

Sub CommandButton1_Click()
'Updated by Extendoffice 20180625
Dim xFileDialog As FileDialog, GetStr(1 To 100) As String '100 files is the maximum applying this code
Dim xFindStr As String
Dim xReplaceStr As String
Dim xDoc As Document
On Error Resume Next
Set xFileDialog = Application.FileDialog(msoFileDialogFilePicker)
With xFileDialog
    .Filters.Clear
    .Filters.Add "All WORD File ", "*.docx", 1
    .AllowMultiSelect = True
    i = 1
    If .Show = -1 Then
        For Each stiSelectedItem In .SelectedItems
            GetStr(i) = stiSelectedItem
            i = i + 1
        Next
        i = i - 1
    End If
    Application.ScreenUpdating = False
    xFindStr = InputBox("Find what:", "Kutools for Word", xFindStr)
    xReplaceStr = InputBox("Replace with:", "Kutools for Word", xReplaceStr)
    For j = 1 To i Step 1
        Set xDoc = Documents.Open(FileName:=GetStr(j), Visible:=True)
        Windows(GetStr(j)).Activate
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = xFindStr  'Find What
            .Replacement.Text = xReplaceStr  'Replace With
            .Forward = True
            .Wrap = wdFindAsk
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
        Application.Run macroname:="NEWMACROS"
        ActiveDocument.Save
        ActiveWindow.Close
    Next
    Application.ScreenUpdating = True
End With
MsgBox "Operation end, please view", vbInformation
End Sub

3 กด F5 กุญแจสำคัญในการเรียกใช้รหัส

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

5. ในครั้งแรก Kutools สำหรับ Word ให้ป้อนข้อความที่คุณจะพบในเอกสารต่างๆลงในไฟล์ สิ่งที่ค้นหา จากนั้นคลิกที่ไฟล์ OK ปุ่ม

6. ในวินาทีที่ Kutools สำหรับ Word กล่องโต้ตอบป้อนข้อความที่คุณจะแทนที่แล้วคลิกไฟล์ OK ปุ่ม

8 คลิกที่ OK ในปุ่มถัดไป Microsoft Word กล่องโต้ตอบเพื่อสิ้นสุดการค้นหาและแทนที่

ในกรณีนี้คำทั้งหมด "Word" ในเอกสารที่เลือกจะถูกแทนที่ด้วย "Excel" พร้อมกัน


ค้นหาและแทนที่ข้อความที่แตกต่างกันในเอกสารหลายฉบับพร้อมกันได้อย่างง่ายดายด้วย Kutools for Word

ที่นี่ขอแนะนำ ค้นหาแบทช์และแทนที่ คุณลักษณะของ Kutools สำหรับ Word. ด้วยคุณสมบัตินี้คุณสามารถค้นหาและแทนที่ข้อความต่างๆในเอกสาร Word หลาย ๆ ชุดในเวลาเดียวกันได้อย่างง่ายดาย มาดูวิธีใช้คุณสมบัตินี้เพื่อค้นหาและแทนที่ข้อความในเอกสาร

Kutools สำหรับ Word : ด้วยโปรแกรมเสริม Word ที่มีประโยชน์มากกว่า 100 รายการ ทดลองใช้ฟรีไม่มีข้อจำกัดใน 60 วัน.

1. กรุณาคลิก Kutools พลัส > ค้นหาแบทช์และแทนที่ เพื่อเปิดใช้คุณลักษณะนี้

2 ใน ค้นหาแบทช์และแทนที่ โปรดกำหนดค่าดังต่อไปนี้

  • 2.1) คลิกปุ่ม เพิ่มแถว ใต้ปุ่ม ค้นหาและแทนที่ แท็บ;
  • 2.2) ในฟิลด์แถวที่สร้างขึ้น:
A. ป้อนข้อความที่คุณจะพบในกล่องข้อความในไฟล์ หา คอลัมน์
B. ป้อนข้อความที่คุณจะแทนที่ลงในกล่องข้อความในไฟล์ แทนที่ คอลัมน์;
C. ระบุประเภทการค้นหาตำแหน่งที่จะค้นหาข้อความและสีเพื่อเน้นข้อความตามที่คุณต้องการ ในกรณีนี้ฉันเลือก การจับคู่คำเต็ม, เอกสารหลัก และสีบางสีจาก ประเภทการค้นหา ค้นหาใน และ เน้น คอลัมน์;
  • 2.3) ทำซ้ำขั้นตอนที่ 2.1 และ 2.2 เพื่อเพิ่มข้อความอื่น ๆ ที่คุณจะพบและแทนที่
  • 2.4) คลิกปุ่ม  ปุ่มใน ชนิดของไฟล์ เพื่อเพิ่มเอกสาร Word ซึ่งคุณจะค้นหาและแทนที่ข้อความ
  • 2.5) คลิกปุ่ม แทนที่ or หา ปุ่ม. ดูภาพหน้าจอ:

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

2. หากคุณคลิกไฟล์ แทนที่ ข้อความที่ระบุทั้งหมดจะถูกแทนที่ด้วยข้อความใหม่ทันทีและผลลัพธ์จะปรากฏใต้ปุ่ม ดูตัวอย่างผลลัพธ์ แถบ

3. หากคุณระบุสีไฮไลต์ในขั้นตอนที่ 2 ข้อความที่ถูกแทนที่ทั้งหมดจะถูกไฮไลต์ด้วยสีที่ระบุและคุณสามารถค้นหาได้อย่างรวดเร็วในเอกสาร

3 ปิด ค้นหาแบทช์และแทนที่ กล่องโต้ตอบ

สำหรับข้อมูลเพิ่มเติมเกี่ยวกับคุณลักษณะนี้โปรด คลิกที่นี่....

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

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

Kutools สำหรับ Word - ยกระดับประสบการณ์คำศัพท์ของคุณด้วย Over 100 คุณสมบัติเด่น!

🤖 Kutools ผู้ช่วย AI: แปลงโฉมงานเขียนของคุณด้วย AI - สร้างเนื้อหา  /  เขียนข้อความใหม่  /  สรุปเอกสาร  /  สอบถามข้อมูล ขึ้นอยู่กับเอกสารทั้งหมดนี้ภายใน Word

📘 ความเชี่ยวชาญด้านเอกสาร: แยกหน้า  /  ผสานเอกสาร  /  ส่งออกตัวเลือกในรูปแบบต่างๆ (PDF/TXT/DOC/HTML...)  /  แบทช์แปลงเป็น PDF  /  ส่งออกเพจเป็นรูปภาพ  /  พิมพ์หลายไฟล์พร้อมกัน...

การแก้ไขเนื้อหา: ค้นหาแบทช์และแทนที่ ข้ามหลายไฟล์  /  ปรับขนาดรูปภาพทั้งหมด  /  ย้ายแถวและคอลัมน์ของตาราง  /  แปลงตารางเป็นข้อความ...

🧹 ทำความสะอาดได้อย่างง่ายดาย: หลบไป พื้นที่พิเศษ  /  แบ่งส่วน  /  ส่วนหัวทั้งหมด  /  กล่องข้อความ  /  เชื่อมโยงหลายมิติ  / หากต้องการดูเครื่องมือถอดเพิ่มเติม โปรดไปที่ของเรา ลบกลุ่ม...

ส่วนแทรกโฆษณา: แทรก ตัวคั่นหลักพัน  /  กล่องกาเครื่องหมาย  /  ปุ่มวิทยุ  /  คิวอาร์โค้ด  /  บาร์โค้ด  /  ตารางเส้นทแยงมุม  /  คำอธิบายสมการ  /  คำบรรยายภาพ  /  คำบรรยายตาราง  /  รูปภาพหลายภาพ  / ค้นพบเพิ่มเติมใน แทรกกลุ่ม...

🔍 การเลือกที่แม่นยำ: ระบุ หน้าที่เฉพาะเจาะจง  /  ตาราง  /  รูปร่าง  /  หัวเรื่องย่อหน้า  / เสริมการนำทางด้วย ข้อมูลเพิ่มเติม เลือกคุณสมบัติ...

การปรับปรุงดาว: นำทางอย่างรวดเร็วไปยังสถานที่ใด ๆ  /  แทรกข้อความซ้ำอัตโนมัติ  /  สลับระหว่างหน้าต่างเอกสารได้อย่างราบรื่น  /  11 เครื่องมือการแปลง...

???? ต้องการลองใช้คุณสมบัติเหล่านี้หรือไม่? Kutools for Word มีไฟล์ ทดลองใช้ฟรี 60 วันโดยไม่มีข้อจำกัด! 🚀
 
Comments (71)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Congrats!!! Your VBA code saves a lot of time. 5*
Rated 5 out of 5
This comment was minimized by the moderator on the site
thanks for -How To Search And Replace Across Multiple Files In Word?

what about from out side (by folder) ?

thanks gain
This comment was minimized by the moderator on the site
This is a great explanation.  Is there a way to change settings, e.g. page size, simultaneously? 
This comment was minimized by the moderator on the site
After pressing F5, I get the following error" "Compile error: User-defined type not defined." Can someone help?
This comment was minimized by the moderator on the site
Hi Monique,Please check if the Microsoft Office Object Library is enabled as shown in the screenshot below.
This comment was minimized by the moderator on the site
This is SUCH a time saving solution. THANK YOU!
One thing that may make it even better, is adding support for subdirectories. (That is: Files in multiple subdirectories)
I am an absolute newbie in this, and don't know the syntax, the parameter, or where to add that.

Could somebody help?
This comment was minimized by the moderator on the site
I need to replace text in multiple Word files and have the replaced text highlighted. Is there a way to do this?
This comment was minimized by the moderator on the site
Hi Daphne,
Why not try the Batch Find and Replace feature of Kutools for Word? It can solve this issue with ease.
This comment was minimized by the moderator on the site
this was a lifesaver thank you so much
This comment was minimized by the moderator on the site
Is it possible to replace in the headers of the word doc?
This comment was minimized by the moderator on the site
Hi Tiago,
Please apply the below VBA code to include the content of headers and footers when finding and replacing texts in multiple documents at once.

Sub CommandButton1_Click()
'Updated by Extendoffice 20180625
Dim xFileDialog As FileDialog, GetStr(1 To 100) As String '100 files is the maximum applying this code
Dim xFindStr As String
Dim xReplaceStr As String
Dim xDoc As Document
On Error Resume Next
Set xFileDialog = Application.FileDialog(msoFileDialogFilePicker)
With xFileDialog
.Filters.Clear
.Filters.Add "All WORD File ", "*.docx", 1
.AllowMultiSelect = True
i = 1
If .Show = -1 Then
For Each stiSelectedItem In .SelectedItems
GetStr(i) = stiSelectedItem
i = i + 1
Next
i = i - 1
End If
Application.ScreenUpdating = False
xFindStr = InputBox("Find what:", "Kutools for Word", xFindStr)
xReplaceStr = InputBox("Replace with:", "Kutools for Word", xReplaceStr)
For j = 1 To i Step 1
Set xDoc = Documents.Open(FileName:=GetStr(j), Visible:=True)
Windows(GetStr(j)).Activate
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = xFindStr 'Find What
.Replacement.Text = xReplaceStr 'Replace With
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run macroname:="NEWMACROS"
If MsgBox("Do you want to replace texts in headers and footers too? ", vbYesNo, "Kutools for Word") = vbYes Then
ActiveWindow.View.SplitSpecial = wdPanePrimaryFooter
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run macroname:="NEWMACROS"
ActiveWindow.View.SplitSpecial = wdPanePrimaryHeader
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run macroname:="NEWMACROS"
End If
ActiveDocument.Save
ActiveWindow.Close
Next
Application.ScreenUpdating = True
End With
MsgBox "Operation end, please view", vbInformation
End Sub
This comment was minimized by the moderator on the site
Is that possible to replace in the header of the word doc?
This comment was minimized by the moderator on the site
Thanks for sharing this information with us.
Word search and replace tool
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