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 / March 2006

Tip: Looking for answers? Try searching our database.

vba code to select all occurrences of some text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
robot - 10 Mar 2006 08:52 GMT
Hello,

I am using Word XP, which allows users the option to "highlight all items
found" in the Find dialog box.

I record a macro for such an action, but the macro would only highlight the
first found item.

l look through the Help file, but could not find any properties/methods of
the Find object that would highlight all found items.

Suggestions are most welcome.
Jonathan West - 10 Mar 2006 09:24 GMT
Unfortunately, Microsoft never made this feature available to VBA.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

> Hello,
>
[quoted text clipped - 9 lines]
>
> Suggestions are most welcome.
Jezebel - 10 Mar 2006 11:37 GMT
The multiple selections are a function of the Selection object, not of the
Find object. Sadly, not available through VBA. See
http://support.microsoft.com/kb/q288424/

> Hello,
>
[quoted text clipped - 9 lines]
>
> Suggestions are most welcome.
Helmut Weber - 10 Mar 2006 12:30 GMT
Hi Robot,

You may utilize highlightcolorindex,
which is a bit more complicated for a beginner,
but in the end, I think, you can use it like
a discontiguous selection.

Sub MyHighlight()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
  .Text = "brown"
  While .Execute
     rDcm.HighlightColorIndex = wdYellow
  Wend
End With
End Sub

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Greg - 10 Mar 2006 13:33 GMT
See:
http://gregmaxey.mvps.org/Find_it_tool_bar.htm

This is an Add-In I wrote about a year ago to do this very thing.
Klaus Linke - 26 Mar 2006 01:04 GMT
> Hello,
>
[quoted text clipped - 9 lines]
>
> Suggestions are most welcome.

The only way to do it would be using SendKeys (which is pretty kludgy and
error-prone):

SendKeys "{TAB}+{TAB}{TAB}{TAB}{ENTER}"
With Dialogs(wdDialogEditFind)
  .Find = "e"
  .Display 1
End With

Klaus
Klaus Linke - 26 Mar 2006 01:41 GMT
> SendKeys "{TAB}+{TAB}{TAB}{TAB}{ENTER}"
> With Dialogs(wdDialogEditFind)
>   .Find = "e"
>   .Display 1
> End With

The "+" should have been in braces {+}, but SendKeys still lives up to its
reputation and doesn't work.

SendKeys "%t{+}{TAB}{TAB}{TAB}{ENTER}"
should work (more or less reliably) in the English version.

Klaus
 
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.