【发布时间】:2020-07-07 05:20:47
【问题描述】:
如何在 Microsoft Word 2010 中使所有合并字段变为粗体?请建议一种使用 VBA 的方法。此外,出现在 if 条件中的合并字段也必须加粗。
【问题讨论】:
如何在 Microsoft Word 2010 中使所有合并字段变为粗体?请建议一种使用 VBA 的方法。此外,出现在 if 条件中的合并字段也必须加粗。
【问题讨论】:
您可以使用查找和替换来录制宏。使用^d 查找所有字段并使用^& 替换为相同的文本,并将格式设置为粗体。在录制之前,通过选择全部并使用 Shift + F9 来切换所有域代码。记录此过程会产生以下 VBA 代码:
Sub MergeBold()
'
' MergeBold Macro
'
'
Selection.WholeStory
Selection.Fields.ToggleShowCodes
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Bold = True
With Selection.Find
.Text = "^d"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.WholeStory
Selection.Fields.ToggleShowCodes
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
【讨论】: