View Single Post
 
Old 03-15-2015, 11:01 AM
AlexandarR AlexandarR is offline Windows XP Office 2003
Novice
 
Join Date: Mar 2015
Location: Chennai, Tamilnadu, India
Posts: 7
AlexandarR is on a distinguished road
Thumbs up Macro to find a text and format it, adding a comment

Quote:
Originally Posted by AlexandarR View Post
It works excellent!!!

Thank you very much!!!

Hi! This Alex again!

I have modified the code slightly, to change the colour and not to replace anything.

code:

Sub z_Abstract()
Dim vFindText As Variant
Dim sReplaceText As String
Dim oRng As Range
Dim oSearch As Range
Dim oFound As Range
Dim i As Long
Dim sAsk As String
Options.DefaultHighlightColorIndex = wdTurquoise
vFindText = Array("I", "we", "us", "our")
sReplaceText = "zzzzz"
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(FindText:="\<ABS\>*\<\/ABS\>", MatchWildcards:=True)
Set oSearch = oRng
For i = 0 To UBound(vFindText)
Set oFound = oSearch
With oFound.Find
Selection.Font.Color = wdColorPink
.ClearFormatting
.Replacement.ClearFormatting
.MatchWholeWord = True
Do While .Execute(FindText:=vFindText(i), _
MatchWholeWord:=True, _
MatchWildcards:=True, _
Forward:=True, _
Wrap:=wdFindStop) = True
'oFound.Text = sReplaceText

oFound.HighlightColorIndex = wdTurquoise
oFound.Font.Color = wdColorPink
oFound.Comments.Add oFound, "CE: The use of personal pronouns (I, we, us, our) is not permitted in the abstract."
oFound.Collapse wdCollapseEnd
If oFound.End >= oSearch.End Then Exit Do
Loop
End With
Next i
Loop
End With
lbl_Exit:
Exit Sub
End Sub

That code finds in order of the array only. i.e. In the following text, the macro finds the text in array only in the same order and it finds a text once only.

<ABS>The use of personal pronouns (our, us, I, we) is not permitted in the abstract. The use of personal pronouns (I, we, us, our) is not permitted in the abstract.

I need to find all occurrences of a [whole] word irrespective of the order, within the coded text.

Please help.

Thanks!
Reply With Quote