2017-11-03 5 views
0

Ich möchte "Proc. Natl. Acad. Sci "in dem Artikel, ihn durch" Proc. Natl. Acad. Sci. USA "und hebt es als grün hervor.
Ich schrieb den folgenden Code. Es nur markiert "Proc. Natl. Acad. Sci. "Als grün und nicht markiert USA als grün. Wie kann ich ganz markieren "Proc. Natl. Acad. Sci. USA "wie grün?Markieren Sie den Ersatz des Inhalts

Sub add_usa() 
    selection.find.clearforamtting 
     With selection.Find 
      .Text = "Proc. Natl. Acad. Sci. " 
      .Wrap = wdFindContinue 
      .Forward = True 
      .MatchCase = False 
      .MatchWildcards = False 
      Do 
       .Execute 
       If .Found And selection.Range.Next(wdCharacter, 1) <> "U" Then 
        selection.Range.InsertAfter "USA " 
        selection.Range.HighlightColorIndex = wdBrightGreen 
       End If 
       If Not .Found Then 
        Exit Do 
       End If 
      Loop 
     End With 

End Sub 

enter image description here

Antwort

1

die Linien Legen Sie über den Bereich innerhalb eines With-Block ändern:

With Selection.Range 
    .InsertAfter "USA " 
    .HighlightColorIndex = wdBrightGreen 
End With 

(Getestet in Word 2010)

1

Sie nur Suchen und Ersetzen verwenden können: -

Sub Add_USA() 

    Const ExistingText As String = "Proc. Natl. Acad. Sci." 
    Const NewText As String = "Proc. Natl. Acad. Sci. USA" 

    Options.DefaultHighlightColorIndex = wdBrightGreen 

    With Selection.Find 
     .ClearFormatting 
     .Replacement.ClearFormatting 
     .Text = ExistingText 
     .Replacement.Text = NewText 
     .Replacement.Highlight = True 
     .Forward = True 
     .Wrap = wdFindContinue 
     .Execute Replace:=wdReplaceAll 
    End With 

End Sub 
Verwandte Themen