Note: The other languages of the website are Google-translated. Back to English
登入  \/ 
x
or
x
註冊  \/ 
x

or

如何在Word文檔中同時查找和替換多個單詞?

Word提供了“查找和替換”功能以查找單詞或短語的所有實例,並同時用新單詞替換它們。 但是,如果您想同時查找和替換不同的單詞,此內置函數將無濟於事。 在本文中,我們討論的是一種VBA方法,用於同時在Word文檔中查找和替換多個不同的單詞。

使用VBA代碼在Word中同時查找和替換多個單詞
借助驚人的功能輕鬆地在Word中同時查找和替換多個單詞


使用VBA代碼在Word中同時查找和替換多個單詞

請執行以下操作以在Word文檔中同時查找和替換多個單詞。

1.打開要查找的Word文檔,並同時替換多個單詞,然後按 其他 + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 在裡面 Microsoft Visual Basic for Applications 窗口中,單擊 插入 > 模塊。 然後將下面的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 for Word 對話框中,輸入將找到的多個單詞並將其替換到文本框中,並用逗號分隔它們,然後單擊 OK 按鈕。 看截圖:

5.在第二 Kutools for Word 對話框中,輸入要替換為的新單詞(這些單詞也需要用逗號分隔),然後單擊 OK 按鈕。

備註: 在這種情況下,所有 “ KTE” 在本文檔中將被替換為 “新”,“ KTO”“ KTW” 將被替換為 “測試”“完”。 請根據您的需要進行更改。


借助驚人的功能輕鬆地在Word中同時查找和替換多個單詞

批量查找和替換 的特點 Kutools for Word 可以幫助您輕鬆地在一個文檔中或同時在多個文檔中查找和替換不同的文本。

在應用此功能之前,請花幾分鐘 首先下載並安裝.

1.啟動Microsoft Word應用程序,單擊 Kutools Plus > 批量查找和替換.

2。 在裡面 批量查找和替換 窗口,請進行以下配置。

  • 2.1點擊 按鈕> 添加文件 or 添加文件夾 添加一個或多個文檔,您將在其中找到並替換多個單詞。
  • 2.2點擊 添加行 按鈕插入查找和替換字段。 如果要同時查找和替換三個不同的文本,請創建三行。
  • 2.3在每一行中,輸入要用新單詞替換的現有單詞。 發現 列,然後將新詞輸入到 更換 列。
  • 2.4指定 搜索類型 每行。
  • 2.5在 查找 列,選擇將查找和替換應用到的位置。 這包括 主要文件, 頁腳 在這個部分。 您可以根據需要選擇其中之一,其中兩個或全部。
  • 2.6。 點擊 更換 按鈕開始操作。 看截圖:

然後,同時在所選文檔中替換特定單詞。

小提示: 您可以通過在 突出 一列。

  如果您想免費試用(60天)此實用程序, 請點擊下載,然後按照上述步驟進行操作。


推薦的Word生產力工具

 

Kutools For Word - 100 多個 Word 高級功能,節省 50% 的時間

  • 複雜和重複的操作可以在幾秒鐘內完成一次處理。
  • 跨文件夾一次將多個圖像插入Word文檔。
  • 將文件夾中的多個Word文件合併並合併為所需順序。
  • 根據標題,分節符或其他條件將當前文檔拆分為單獨的文檔。
  • 在Doc和Docx之間,Docx和PDF之間轉換文件,用於常見轉換和選擇的工具集合等...
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    excel guy · 2 months ago
    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.
  • To post as a guest, your comment is unpublished.
    Vern · 7 months ago
    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?
  • To post as a guest, your comment is unpublished.
    AJs · 8 months ago
    What if I'm trying to replace commas?
    • To post as a guest, your comment is unpublished.
      crystal · 8 months ago
      The VBA code can't help to replace commas. You can apply Kutools to achieve.
  • To post as a guest, your comment is unpublished.
    Ajs · 8 months ago
    After hitting Replace it just goes to Preview and doesn't do anything further.
    • To post as a guest, your comment is unpublished.
      crystal · 8 months ago
      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.
  • To post as a guest, your comment is unpublished.
    Walter Mendes · 1 years ago
    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?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi,
      The Batch Find and Replace feature of Kutools for Word can perfectly solve your problem, you can have a try.
  • To post as a guest, your comment is unpublished.
    JM · 1 years ago
    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
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      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.
  • To post as a guest, your comment is unpublished.
    Ranjit Jagtap · 1 years ago
    How to find and select multiple words at the same time
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      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.
  • To post as a guest, your comment is unpublished.
    Shailesh Pateliya · 2 years ago
    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.
    • To post as a guest, your comment is unpublished.
      Kirill · 8 months ago
      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.

  • To post as a guest, your comment is unpublished.
    Adam · 2 years ago
    Any way to make this case sensitive?
  • To post as a guest, your comment is unpublished.
    rishabh jain · 2 years ago
    will this work in office Excel 365
  • To post as a guest, your comment is unpublished.
    jaka1 · 2 years ago
    Toto jsem hledal, jen potřebuji pro hledaný text přidat nějaké formátování. Jak toho dosáhnu?