合并字段Bold Word 2010

时间:2014-05-05 21:01:55

标签: ms-word word-vba mailmerge

如何在Microsoft Word 2010中使所有合并字段变为粗体?请建议使用VBA的方法。此外,如果条件中出现的合并字段也必须变为粗体。

1 个答案:

答案 0 :(得分:0)

您可以使用查找和替换来录制宏。使用^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