Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2008

Tip: Looking for answers? Try searching our database.

How highlighting all found items with a macro?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
avkokin - 17 Feb 2008 08:24 GMT
Hello. The Dialog Box of "Find and Replace" (Tab "Find") including the
field with the text "Highlight all items found in...".  I need to
select all found words with help macro but I not know how I do it. I
wrote code of searching and highlighting next item but not all items:

With Selection.Find
   .ClearFormatting
   .Text = Selection.Text
   .Replacement.ClearFormatting
   .Replacement.Text = ""
   .Forward = True
   .Wrap = wdFindContinue
   .Format = False
   .MatchCase = False
   .MatchWholeWord = False
   .MatchAllWordForms = False
   .Execute
End With

How highlighting all found items?  Thank you very much.
Helmut Weber - 17 Feb 2008 08:43 GMT
Hi Avkokin,

like that:

Sub Test6()
Dim rTmp As Range
Set rTmp = ActiveDocument.Range
Options.DefaultHighlightColorIndex = wdRed
With rTmp.Find
  .Text = "lazy"
  .Replacement.Text = "lazy"
  .Replacement.Highlight = True
  .Execute Replace:=wdReplaceAll
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
Graham Mayor - 17 Feb 2008 08:49 GMT
Do you want to *highlight* ie with a colour, all items found? In which case

Sub ReplaceExample()
Dim sFindText As String
sFindText = InputBox("Find what?")
   With Selection
       .HomeKey Unit:=wdStory
       With .Find
           .ClearFormatting
           .Replacement.ClearFormatting
'**********************
           .Text = sFindText
           .Replacement.Text = "^&"
           .Replacement.Highlight = True
'**********************
           .Forward = True
           .Wrap = wdFindContinue
           .Format = True
           .MatchCase = False
           .MatchWholeWord = False
           .MatchAllWordForms = False
           .MatchSoundsLike = False
           .MatchWildcards = False
           .Execute replace:=wdReplaceAll
       End With
   End With
End Sub

or

Do you want to *select* all items found? The Find dialog does this, so why
do you need to re-invent the wheel? If you want to process the found items
then a macro would do so individually.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Hello. The Dialog Box of "Find and Replace" (Tab "Find") including the
> field with the text "Highlight all items found in...".  I need to
[quoted text clipped - 16 lines]
>
> How highlighting all found items?  Thank you very much.
avkokin - 17 Feb 2008 10:05 GMT
> Do you want to *highlight* ie with a colour, all items found? In which case
>
[quoted text clipped - 60 lines]
>
> - Show quoted text -

Yes, I just want to *select* all items found but not color. Thank you
for your help.
avkokin - 17 Feb 2008 10:08 GMT
> > Do you want to *highlight* ie with a colour, all items found? In which case
>
[quoted text clipped - 65 lines]
>
> - Show quoted text -

And I want to do it with my macro but not use all times dialog box.
Helmut Weber - 17 Feb 2008 11:22 GMT
Hi  Anton,

I can't find a way to set the option
"highlight all ..." in a macro.

It isn't of much use anyway,
as this so called discontiguous selection
can not, in my humble opinion, be accessed programmatically.

Try
msgbox selection.words.count

Whatever number of words is selected,
the msgbox always returns "1",
of course, if at least one string was found.

Therefore, what Graham and I suggested,
might be preferable.
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
Jay Freedman - 17 Feb 2008 17:04 GMT
>Hi  Anton,
>
[quoted text clipped - 14 lines]
>Therefore, what Graham and I suggested,
>might be preferable.

You're exactly correct, Helmut. VBA has very little understanding of
discontiguous selections (http://support.microsoft.com/?kbid=288424) and it
can't create them at all.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.