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

จะค้นหาและแทนที่คำหลายคำพร้อมกันในเอกสาร Word ได้อย่างไร?

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

ค้นหาและแทนที่คำหลายคำในเวลาเดียวกันใน Word ด้วยรหัส VBA
ค้นหาและแทนที่คำหลายคำพร้อมกันใน Word ได้อย่างง่ายดายด้วยคุณสมบัติที่น่าทึ่ง


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

โปรดทำดังนี้เพื่อค้นหาและแทนที่คำหลายคำในเวลาเดียวกันในเอกสาร Word

1. เปิดเอกสาร Word ที่คุณต้องการค้นหาและแทนที่คำหลายคำพร้อมกันจากนั้นกดปุ่ม อื่น ๆ + F11 คีย์เพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

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

รหัส VBA: ค้นหาและแทนที่คำหลายคำพร้อมกันใน Word

Sub FindAndReplaceMultiItems()
'Update by ExtendOffice 2018/10/25
    Dim xFind As String
    Dim xReplace As String
    Dim xFindArr, xReplaceArr
    Dim I As Long
    Application.ScreenUpdating = False
    xFind = InputBox("Enter items to be found here,seperated by comma: ", "Kutools for Word")
    xReplace = InputBox("Enter new items here, seperated by comma: ", "Kutools for Word")
    xFindArr = Split(xFind, ",")
    xReplaceArr = Split(xReplace, ",")
    If UBound(xFindArr) <> UBound(xReplaceArr) Then
        MsgBox "Find and replace characters must be equal.", vbInformation, "Kutools for Word"
        Exit Sub
    End If
    For I = 0 To UBound(xFindArr)
        Selection.HomeKey Unit:=wdStory
        With Selection.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = xFindArr(I)
            .Replacement.Text = xReplaceArr(I)
            .Format = False
            .MatchWholeWord = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    Next
    Application.ScreenUpdating = True
End Sub

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

4. ในครั้งแรก Kutools สำหรับ Word กล่องโต้ตอบป้อนคำหลายคำที่คุณจะพบและแทนที่ลงในกล่องข้อความและคั่นด้วยลูกน้ำจากนั้นคลิก OK ปุ่ม. ดูภาพหน้าจอ:

5. ในวินาทีที่ Kutools สำหรับ Word กล่องโต้ตอบป้อนคำใหม่ที่คุณจะแทนที่ (คำเหล่านี้ต้องคั่นด้วยเครื่องหมายจุลภาค) จากนั้นคลิก OK ปุ่ม

หมายเหตุ ในกรณีนี้ทั้งหมด “ KTE” ในเอกสารนี้จะถูกแทนที่ด้วย "ใหม่", และ “ KTO” และ “ KTW” จะถูกแทนที่ด้วย "ทดสอบ" และ "เสร็จสิ้น". โปรดเปลี่ยนตามความต้องการของคุณ


ค้นหาและแทนที่คำหลายคำพร้อมกันใน Word ได้อย่างง่ายดายด้วยคุณสมบัติที่น่าทึ่ง

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

ก่อนใช้คุณลักษณะนี้โปรดสละเวลาสักครู่เพื่อ ดาวน์โหลดและติดตั้งในตอนแรก.

1. เปิดโปรแกรม Microsoft Word คลิก Kutools พลัส > ค้นหาแบทช์และแทนที่.

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

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

จากนั้นคำเฉพาะจะถูกแทนที่ในเอกสารที่เลือกพร้อมกัน

เคล็ดลับ: คุณสามารถเน้นผลลัพธ์ด้วยสีพื้นหลังโดยระบุสีที่ต้องการในไฟล์ เน้น คอลัมน์สำหรับแถว

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

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

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

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

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

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

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

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

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

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

???? ต้องการลองใช้คุณสมบัติเหล่านี้หรือไม่? Kutools for Word มีไฟล์ ทดลองใช้ฟรี 60 วันโดยไม่มีข้อจำกัด! 🚀
 
Comments (23)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
The VBA script you provide here seems to work only for Latin characters; is there some workaround to get special characters to work.
I work with Sanskrit, which used the Devanagari script, similar to Hindi. (1) The VBA does not accept the Devanagai font nor does it find the Latin characters with diacriticals. For example: It fails miserably if I search for mūlādhāra (मूलाधार). It doesn't seem to recognize the ū or ā, for example, and the Devanagari is a complete loss.

Moreover, does the script recognize spaces between words? If not, how do I get them in there?

Thank you!
This comment was minimized by the moderator on the site
Chào bạn, có cách nào thay thế RẤT NHIỀU cụm từ bằng RẤT NHIỀU cụm từ khác (nhập từng cụm từ rất mất thời gian) bằng cách m lập một file trong đó có 2 cột, 1 cột là cụm từ nguồn và cột 2 là cụm từ đích được không? rất cám ơn bạn.
This comment was minimized by the moderator on the site
Hi Nguyễn Phúc Lâm,
I recommand you apply the Batch Find and Replace feature of Kutools for Word (the second method in this post) to solve this problem.
In the Find and Replace dialog box, after creating the two columns you need, you can save the current settings as a scenaria for future use.
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/find_and_replace.png
This comment was minimized by the moderator on the site
Cám ơn Crystal, cách này có thể áp dụng với một số lượng nhỏ các cụm từ, nếu với số lượng các cụm từ lớn (hơn 1000, hơn 10000.. cụm từ) thì rất khó để có thể nhập thủ công. Vậy có cách nào khác không bạn? Cám ơn bạn đã trả lời
This comment was minimized by the moderator on the site
Hi Nguyễn Phúc Lâm,
Temporarily unable to deal with this problem with VBA code as it is a bit complex. This feature will be considered for upgrade in the next release. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
Thanks for the project, Could you make it the way we can also replace letters in words. For example if i want to change Dollar as DoLLar it does not function.
This comment was minimized by the moderator on the site
In the first instruction (Find And Replace Multiple Words At The Same Time In Word With VBA Code), it does not find instances where the word to be replaced falls in the middle of a word (For example, .com following a website name). Can this be modified to do so?
This comment was minimized by the moderator on the site
What if I'm trying to replace commas?
This comment was minimized by the moderator on the site
The VBA code can't help to replace commas. You can apply Kutools to achieve.
This comment was minimized by the moderator on the site
After hitting Replace it just goes to Preview and doesn't do anything further.
This comment was minimized by the moderator on the site
Hi Ajs,All required words have been successfully replaced at once after hitting the Replace button. It goes to the Preview tab to help you know how many words have been successfully replaced. After that, close the dialog box.
This comment was minimized by the moderator on the site
Hi! First, congratulations for your work: this macro is very useful and interesting! I would like, neverthless, you help me with one thing. I am a proofreader and would like the replacements would highlithed in green or red color. How can I do this? Is there a code line I could use?
This comment was minimized by the moderator on the site
Hi, The Batch Find and Replace feature of Kutools for Word can perfectly solve your problem, you can have a try.
This comment was minimized by the moderator on the site
Hi how can this macro be revised to take more key words? I have about 170 words that I wold like to find and replace
This comment was minimized by the moderator on the site
Hi JM,
After running the code, a Kutools for Excel dialog box will pop up, please enter the keywords you will find and separate them with commas.
This comment was minimized by the moderator on the site
How to find and select multiple words at the same time
This comment was minimized by the moderator on the site
Hi,
After running the code, a Kutools for Excel dialog box will pop up, please enter the keywords you will find and separate them with commas.
This comment was minimized by the moderator on the site
Hi, This works well with English Words. Now I am doing a document where I translate English to Gujarati. So, when I apply this, (Find English Words) and (Replace with Gujarati words), it does change but it appears like "???". Doesn't show the Gujarati word but just question marks? Any further help? Please.
This comment was minimized by the moderator on the site
I'm have a similar problem with Sanskrit, not only the Devanagari script but also the English/Latin diacriticals on the special characters like ā, ū, ṛ, ṁ, ṃ, etc. Any suggestions for a workable fix?
This comment was minimized by the moderator on the site
Hello Shailesh, facing the same issue. Did you find a solution to it. Am also trying to figure out how to change from Chinese to English.
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