按住 Alt + F11 開啟 Microsoft Visual Basic for Applications 視窗。
點擊 插入 > 模組,然後將以下程式碼複製並貼到空白模組中:
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 "Can't be empty!", vbInformation, "Kutools for Word"
Exit Sub
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
插入程式碼後,按下 F5 執行程式碼。會彈出一個對話框,要求您輸入要加粗的字詞。
點擊「確定」,文件中所有指定的字詞都會以加粗格式顯示。
使用 Kutools for Word 在 Word 文件中將多個字詞的所有實例加粗
與使用 VBA 不同,Kutools for Word 提供了一種更簡單的方法,通過其 批量替換 功能一次加粗多個字詞。當您想一次性對多個特定字詞應用加粗格式且無需編寫任何程式碼時,此方法非常完美。