跳到主要內容

如何在Word文檔中以粗體顯示同一單詞的所有實例?

如果您的Word文件中有多個“外表”文本,現在您需要將所有“外表”文本設置為粗體格式。 您如何盡快在大型Word文檔中加粗同一單詞的所有實例?

用VBA代碼加粗Word文檔中同一單詞的所有實例


用VBA代碼加粗Word文檔中同一單詞的所有實例

以下VBA代碼可以幫助您快速輕鬆地將特定單詞的所有實例加粗,請這樣做:

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 然後,單擊 插入 > 模塊,將以下代碼複製並粘貼到打開的空白模塊中:

VBA代碼:加粗同一單詞的所有實例

Sub BoldAll()
    Dim xStr As String
    xStr = InputBox("Please enter the word that you want to bold:", "KuTools for Word")
    If Trim(xStr) = "" Then
        MsgBox "Cann’t be empty!", vbInformation, "KuTools for Word"
    End If
    With ActiveDocument.Content.Find
        .ClearFormatting
        .Text = xStr
        .Replacement.ClearFormatting
        .Replacement.Font.Bold = True
        .Replacement.Text = "^&"
        .Wrap = wdFindStop
        .Format = True
        .Forward = True
        .Execute Replace:=wdReplaceAll
    End With
End Sub

3。 插入代碼後,然後按 F5 鍵運行它,並彈出一個對話框,提醒您插入要加粗的單詞,請參見屏幕截圖:

doc粗體字1

4。 然後,單擊 OK 按鈕,所有的特定單詞都立即被設置為粗體。

最佳辦公生產力工具

Kutools for Word - 透過 Over 提升您的文字體驗 100 顯著特點!

🤖 Kutools 人工智慧助手:用人工智慧改變你的寫作 - 生成內容  /  重寫文字  /  總結文件  /  查詢資料 基於文檔,全部在Word中

📘 文件掌握: 分頁  /  合併文件  /  以各種格式匯出選擇(PDF/TXT/DOC/HTML...)  /  批次轉換為PDF  /  將頁面匯出為圖像  /  一次列印多個文件...

內容編輯: 批量查找和替換 跨多個文件  /  調整所有圖片的大小  /  轉置表行和列  /  將表格轉換為文字...

🧹 輕鬆清潔: 移開 多餘的空間  /  分節符  /  所有標題  /  文本框  /  超鏈接  / 如需更多拆卸工具,請前往我們的 刪除組...

創意插入: 插入 千位分隔符  /  複選框  /  單選按鈕  /  QR Code  /  條碼  /  對角線表  /  公式標題  /  圖片說明  /  表格標題  /  多張圖片  / 發現更多 插入組...

🔍 精準選擇:精確定位 特定頁面  /    /  形狀  /  標題段落  / 增強導航功能 更多 選擇功能...

星級增強: 快速導航至任何位置  /  自動插入重複文字  /  在文檔視窗之間無縫切換  /  11 轉換工具...

???? 想嘗試這些功能嗎? Kutools for Word 提供了 60天免費試用,沒有任何限制! 🚀
 
Comments (4)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Que isso, salvou meu dia no escritório. Muito obrigado!
This comment was minimized by the moderator on the site
Using Google Translate, this is what Stef had said,
"Hello and thank you for this piece of VBA code.

I work on documents that contain keywords explained like this <#myKeyword>
I would like to identify and bold all the elements that are between < and >.

Is this possible in VBA and could you guide me?

Best to you. (A friendly regard used between people who exchange services or information.)

Stef"

Separately, I, Kaitlyn, was wondering if I could use code to bold all questions.
This comment was minimized by the moderator on the site
Bonjour et merci pour ce bout de code VBA.

Je travaille sur des documents qui contiennent des mots clés explicités de la sorte <#monMotClé>
je souhaiterais repérer et mettre en gras tous les éléments qui se trouvent entre < et >.

est-ce que cela est possible en VBA et pourriez vous me guider ?

Bien à vous.

Stef
This comment was minimized by the moderator on the site
Hello, Stef,
Sorry, I can't understand your question clearly, could you explain your problem in English?
Thank you!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations