Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
Programming
 EXP Systems Forum : PDF reDirect : Programming
Topic: Find ONLY particular Highlighted words - VBA Post Reply Post New Topic
Author Message
vamshivemula
Newbie
Newbie
Avatar

Joined: 21 Feb 10
Location: India
Posts: 2
Quote vamshivemula Replybullet Topic: Find ONLY particular Highlighted words - VBA
    Posted: 21 Feb 10 at 10:21PM
Hi,

I need a help with VBA code where ONLY one particular color highlighted text is selected (for instance a word highlighted in BRIGHT Green (wdBrightGreen)) and the color is removed for the selected text. I used the below code to remove the highlight which follows after the find code, but the code I used find all the highlighted text irrespective of what color it is:

While Selection.Find.Execute = True
Selection.Range.HighlightColorIndex = wdNoHighlight
Wend

I need this in two ways. First is to select all Bright Green highlighted text and remove the highlight in one instance in whole document and the second is to find one word at time and remove only one time so that I can have proper control. I used the following macro code which does not allow me to select particular color but finds the text whichever is highlighted.

Public Sub callChoice()
If MyFrm.optWord.Value = True Then
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Highlight = True
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = False
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
ElseIf MyFrm.optDoc.Value = True Then
Unload MyFrm
Application.ScreenUpdating = False

Selection.WholeStory
Options.DefaultHighlightColorIndex = wdNoHighlight
Selection.Range.HighlightColorIndex = wdNoHighlight
MsgBox ("All the highlights in the Document are removed")
Selection.HomeKey Unit:=wdStory

Application.ScreenUpdating = True
End If
End Sub


Croos-posting links:
http://www.exp-systems.com/Forum_exp/forum_posts.asp?TID=580
http://www.vbaexpress.com/forum/showthread.php?p=206338#post206338
http://www.thecodecage.com/forumz/members-word-vba-programming/181336-find-only-particular-highlighted-words-visual-basic-applications.html#post650165

IP IP Logged
Michel_K17
Moderator Group
Moderator Group
Avatar
Forum Administrator

Joined: 25 Jan 03
Posts: 1673
Quote Michel_K17 Replybullet Posted: 22 Feb 10 at 12:45PM
Hi,

   This forum is for users of PDF reDirect Pro, and how to use the ActiveX component for that product in VBA and other languages.

   I think your question is for Word VBA, and should be addressed in a different forum such as [here].

   Best regards,
Michel Korwin-Szymanowski
EXP Systems LLC
IP IP Logged
vamshivemula
Newbie
Newbie
Avatar

Joined: 21 Feb 10
Location: India
Posts: 2
Quote vamshivemula Replybullet Posted: 22 Feb 10 at 1:57PM
Below is the solution for the above problem.  This solution has been provided by FUMEI (VBAX Expert) at http://www.vbaexpress.com/forum/showthread.php?p=206338#post206338.

Thanks a lot to FUMEI :-)

Sub Highlight()
    Dim r As Range
    Set r = ActiveDocument.Range
     
    With r.Find
        .Highlight = True
        Do While .Execute(FindText:="", Forward:=True) = True
            If r.HighlightColorIndex = wdBrightGreen Then
                r.HighlightColorIndex = wdAuto
                r.Collapse 0
            End If
        Loop
    End With
End Sub
 
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum