Hoppa till huvudinnehåll

Hur hittar jag och ersätter flera ord samtidigt i ett Word-dokument?

Word erbjuder en Sök och ersätt-funktion för att hitta alla instanser av ett ord eller en fras och ersätta dem med ett nytt ord samtidigt. Men om du vill hitta och ersätta olika ord samtidigt kan den här inbyggnadsfunktionen inte hjälpa. I den här artikeln pratar vi om en VBA-metod för att hitta och ersätta flera olika ord samtidigt i Word-dokument.

Hitta och ersätt flera ord samtidigt i Word med VBA-kod
Hitta och ersätt enkelt flera ord samtidigt i Word med en fantastisk funktion


Hitta och ersätt flera ord samtidigt i Word med VBA-kod

Gör så här för att hitta och ersätta flera ord samtidigt i ett Word-dokument.

1. Öppna Word-dokumentet du vill hitta och ersätt flera ord samtidigt och tryck sedan på andra + F11 nycklar för att öppna Microsoft Visual Basic för applikationer fönster.

2. I Microsoft Visual Basic för applikationer fönstret klickar Insert > Modul. Kopiera sedan VBA-koden nedan till modulfönstret.

VBA-kod: Hitta och ersätt flera ord samtidigt i 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. tryck på F5 för att köra koden.

4. I den första Kutools för Word dialogrutan, ange flera ord som du hittar och ersätt i textrutan och separera dem med komma och klicka sedan på OK knapp. Se skärmdump:

5. På sekunden Kutools för Word dialogrutan, ange de nya orden du ska ersätta med (dessa ord måste också separeras med kommatecken) och klicka sedan på OK knapp.

Notera: I det här fallet, alla "KTE" i detta dokument kommer att ersättas med "Ny", och "KTO" och "KTW" kommer att ersättas med "Testa" och "Avsluta". Ändra dem efter dina behov.


Hitta och ersätt enkelt flera ord samtidigt i Word med en fantastisk funktion

Smakämnen Batch Hitta och ersätt egenskap av Kutools för Word kan hjälpa till att enkelt hitta och ersätta olika texter i ett dokument eller över flera dokument samtidigt.

Innan du tillämpar den här funktionen, ta några minuter till ladda ner och installera det först.

1. Starta Microsoft Word-applikationen, klicka på Kutools Plus > Batch Hitta och ersätt.

2. I Batch Hitta och ersätt konfigurera på följande sätt.

  • 2.1 klicka på knapp> Lägg till fil or lägg till mapp för att lägga till ett eller flera dokument där du hittar och ersätter flera ord.
  • 2.2 Klicka på Lägg till rad -knappen för att infoga sök- och ersättningsfälten. Skapa tre rader om du vill hitta och ersätta tre olika texter samtidigt.
  • 2.3 I varje rad anger du de befintliga orden som du kommer att ersätta med en ny i hitta och ange sedan de nya orden i ersätta kolonn.
  • 2.4 Ange Söktyp för varje rad.
  • 2.5 I Hitta i välj var du ska söka och ersätta. Det inkluderar Huvuddokument, Sidhuvud och Sidfot i denna avdelning. Du kan välja en av dem, två av dem eller alla baserat på dina behov.
  • 2.6. Klicka på ersätta för att starta operationen. Se skärmdump:

Sedan ersätts de specifika orden samtidigt i valda dokument.

Dricks: Du kan markera resultatet med bakgrundsfärg genom att ange viss färg i Markera kolumn för en rad.

  Om du vill ha en gratis provperiod (60 dagar) av det här verktyget, klicka för att ladda ner den, och gå sedan till för att tillämpa operationen enligt ovanstående steg.

Bästa kontorsproduktivitetsverktyg

Kutools för Word - Höj din ordupplevelse med Over 100 Anmärkningsvärda funktioner!

🤖 Kutools AI Assistant: Förvandla ditt skrivande med AI - Generera innehåll  /  Skriv om text  /  Sammanfatta dokument  /  Fråga för information baserat på dokument, allt i Word

📘 Dokumentbehärskning: Dela sidor  /  Sammanfoga dokument  /  Exportera urval i olika format (PDF/TXT/DOC/HTML...)  /  Batchkonvertera till PDF  /  Exportera sidor som bilder  /  Skriv ut flera filer samtidigt...

Innehållsredigering: Batch Hitta och ersätt över flera filer  /  Ändra storlek på alla bilder  /  Transponera tabellrader och kolumner  /  Konvertera tabell till text...

🧹 Enkel rengöring: Svep bort Extra utrymmen  /  Avsnitt bryter  /  Alla rubriker  /  Textrutor  /  Hyperlänkar  / För fler borttagningsverktyg, gå till vår Ta bort gruppen...

Kreativa inlägg: Föra in Tusen avskiljare  /  Kryssrutor  /  radio Knappar  /  QR-kod  /  Streckkod  /  Diagonal linjebord  /  Bildtext för ekvation  /  Bild Bildtext  /  Tabelltextning  /  Flera bilder  / Upptäck mer i Infoga grupp...

🔍 Precisionsval: Precisera specifika sidor  /  Tabellerna  /  former  /  rubrikerna  / Förbättra navigering med mer Välj funktioner...

Stjärnförbättringar: Navigera snabbt till vilken plats som helst  /  infoga repetitiv text automatiskt  /  växla sömlöst mellan dokumentfönster  /  11 Konverteringsverktyg...

👉 Vill du prova dessa funktioner? Kutools för Word erbjuder en 60-dagars gratis försök, utan begränsningar! 🚀
 
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