VBA Replacing Highligted text with other text in WORD

3 views
Skip to first unread message

Neeraj Shinde

unread,
Jun 4, 2005, 5:44:37 AM6/4/05
to ProgrammingGuru
 
My VBA Code :
________________________________________
 
Sub ReplaceHighlightedText()
   
    Dim Hran As Range
    Set Hran = ActiveDocument.Range
    ''Replaces the highlighted text with Specific text
nextsearch:
    With Hran.Find
            '.Text = Harr(1)
            .Forward = True
            .Wrap = wdFindAsk
            .Highlight = True
            .Wrap = wdFindStop
            .Execute
            If Hran.Find.Found = True Then
                Hran.Select
                With ActiveDocument.Application.Selection
                    Select Case .Range.HighlightColorIndex
                        Case 4 'green
                            .Text = "author="""""
                            .Range.HighlightColorIndex = wdNoHighlight
                        Case 3  'blue
                            .Text = "title="""""
                            .Range.HighlightColorIndex = wdNoHighlight
                        Case 5  'pink
                            .Text = "<roman num=""19"" type=""century""/><sup>e</sup>"
                            .Range.HighlightColorIndex = wdNoHighlight
                        Case 15 'ARCU
                            .Text = "<initials>ARCU</initials>"
                            .Range.HighlightColorIndex = wdNoHighlight
                        Case 7 'yellow
                            .Text = "<insertion>arcu</insertion>"
                            .Range.HighlightColorIndex = wdNoHighlight
                    End Select
                End With
                Hran.Start = ActiveDocument.Application.Selection.Range.End + 1
                Hran.End = ActiveDocument.Range.End
                GoTo nextsearch
            End If
    End With
   
End Sub
 
 
Neeraj Shinde
Reply all
Reply to author
Forward
0 new messages