使用VBA包装查找和替换MS Word Shape中的文本

时间:2016-04-01 14:11:45

标签: vba ms-word word-vba

我已经启动了一个VBA脚本,它执行通配符查找/替换,并且(A)围绕每个找到的不同颜色边框的文本迭代,然后(B)用空格替换参考字符。但对于(A),我想将找到的文本迭代添加到特定的Word形状,而不是添加彩色边框。以下是我的代码。您能否提供有关如何在下面的脚本中使用VBA将找到的文本添加到MS Word形状的指导?

Sub findAndFormatRanking()
'FORMAT RANKING 1
'Selection.Find.ClearFormatting
With Selection.Find
    .Text = "11_*_11"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
End With
While Selection.Find.Execute

    Selection.Borders.OutsideColor = wdColorGreen
    Selection.Borders.OutsideLineStyle = wdLineStyleSingle
    Selection.Borders.OutsideLineWidth = wdLineWidth300pt
    Selection.Font.ColorIndex = wdGreen
Wend
With Selection.Find
    .ClearFormatting
    .Text = "11_"
    .Replacement.Text = " "
    .Execute Replace:=wdReplaceAll, Forward:=True, _
        Wrap:=wdFindContinue
End With
With Selection.Find
    .ClearFormatting
    .Text = "_11"
    .Replacement.Text = " "
    .Execute Replace:=wdReplaceAll, Forward:=True, _
        Wrap:=wdFindContinue
End With

更新澄清4/6/2016:在我上面的While循环中,当它在符号之间找到匹配的文本时,我想在添加/绘制时用一个片段替换我的3行代码添加边框颜色片段我选择的形状。如果你不认为这是可能的,请告诉我,我会结束这个问题。

0 个答案:

没有答案