如何格式化突出显示的文本

时间:2013-02-03 22:12:19

标签: vba

我在ms-word 2007中使用宏

我必须找到双字母。例如:苹果中的PP,cc&访问中的ss(来自“aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv, WW,XX,YY,ZZ“) 并将上面的双字母Font格式化为比例 - 75%,间距 - 扩展,By - 0.5pt

我有vb代码来突出显示双字母,但我没有选择&的代码将上面的双字母Font格式化为scale - 75%,spacing - expanded,By - 0.5pt

Sub Macro_test()
'
' Macro_alphabet Macro
'
'
Application.ScreenUpdating = False
Dim StrFnd As String, Rng As Range, i As Long
StrFnd = "aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz"
For i = 0 To UBound(Split(StrFnd, ","))
  Set Rng = ActiveDocument.Range
  With Rng.Find
    .ClearFormatting
    .text = Split(StrFnd, ",")(i)
    .Replacement.ClearFormatting
    .Replacement.Highlight = True
    .Replacement.text = "^&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
    Selection.Range.HighlightColorIndex = wdNoHighlight
  End With
Next
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub

1 个答案:

答案 0 :(得分:0)

正如PeterL所说,你可以录制宏。

这是它的样子

        With Selection.Font
            .Spacing = 0.5
            .Scaling = 75
        End With

您可能需要稍微修改为“与rng.font”或类似的匹配您的选择方法。