跳到主要内容

如何在Word文档中以粗体显示同一单词的所有实例?

如果您的Word文件中有多个“外表”文本,现在您需要将所有“外表”文本设置为粗体格式。 您如何尽快在大型Word文档中加粗同一单词的所有实例?

使用VBA代码将Word文档中同一单词的所有实例加粗


使用VBA代码将Word文档中同一单词的所有实例加粗

以下VBA代码可以帮助您快速轻松地将特定单词的所有实例加粗,请执行以下操作:

1。 按住 ALT + F11 键打开 Microsoft Visual Basic应用程序 窗口。

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  /  将页面导出为图像  /  一次打印多个文件...

内容编辑: 批量查找和替换 跨多个文件  /  调整所有图片的大小  /  转置表行和列  /  将表格转换为文字...

🧹 轻松清洁: 移开 多余的空间  /  分节符  /  所有标题  /  文本框  /  超链接  / 如需更多拆卸工具,请前往我们的 删除组...

创意插入: 插 千位分隔符  /  复选框  /  单选按钮  /  扫码支付  /  条码  /  对角线表  /  公式标题  /  图片说明  /  表标题  /  多张图片  / 发现更多 插入组...

🔍 精准选择:精确定位 特定页面  /    /  形状  /  标题段落  / 增强导航功能 更多 选择功能...

星级增强: 快速导航至任何位置  /  自动插入重复文本  /  在文档窗口之间无缝切换  /  11 转换工具...

👉 想尝试这些功能吗? Kutools for Word 提供了 60-day免费试用,没有任何限制! 🚀
 
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