使用VBA进行单词选择文本并使其变为粗体

Aar*_*ron 2 vba word-vba

我每周都会制作几页单词文档.我从PDF中复制文本并将其粘贴到word文档中,然后格式化我粘贴的文本.

这需要很长时间,我想自动化它.

我需要一个宏或一些代码来选择特定的文本,然后使该文本变为粗体.我需要加粗的具体文字就是我所说的废品代码.

有60种不同的代码.例如"FIPS"或"LILL".

Dr.*_*ius 6

像这样的东西:

Sub A()
'
' a Macro
'
'
Dim A(3) As String

A(1) = "code1"
A(2) = "code2"
A(3) = "code3"

For i = 1 To 3
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
       .Forward = True
       .Wrap = wdFindStop
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
       .Replacement.Font.Bold = True

       .Execute FindText:=A(i), ReplaceWith:=A(i), Format:=True, _
         Replace:=wdReplaceAll

    End With
Next i
End Sub  
Run Code Online (Sandbox Code Playgroud)

HTH!

编辑

将美元金额换成粗体

Sub a()
'
' a Macro
'
'
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Bold = True
    With Selection.Find
        .Text = "$([0-9.,]{1,})"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Run Code Online (Sandbox Code Playgroud)