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 / June 2007

Tip: Looking for answers? Try searching our database.

Multiple text selection in Word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Igor - 22 Jun 2007 05:57 GMT
Hi everyone!

I have a small problem; please help me to solve it if somebody knows.

I have to find and select all occurrences of any string in Word document.
I'm working with Word document by OLE.
The sample code is :
If (oWord_FoundRange.Find.Execute("Any string", , , , , , True)) Then
  oWord_FoundRange.Select
End If
oWord_Document.Activate

But it selects only the first occurrence of searching string. I have to
highlight all occurrences. In addition, I have not to change the document,
colors etc.

On other words, I have to simulate the same behavior like check box of the
Word 2003 of the Find window "Select all elements, found in".

Please, help me!

Thanks!

Igor.
Shauna Kelly - 22 Jun 2007 13:45 GMT
Hi Igor

As far as I know, Word's object model does not expose any methods or
properties to allow you to select multiple ranges. As you said, you can do
it through the UI, but it's not possible in code.

Hope this helps.

Shauna Kelly.  Microsoft MVP.
http://www.shaunakelly.com/word

> Hi everyone!
>
[quoted text clipped - 20 lines]
>
> Igor.
Igor - 22 Jun 2007 14:01 GMT
Thanks!

I think, I found another option to highlight multiple ranges. Just add
bookmarks and highlight each of them.

Best regards!

> Hi Igor
>
[quoted text clipped - 31 lines]
> >
> > Igor.
Klaus Linke - 22 Jun 2007 15:05 GMT
Word 2007 has a new .HitHighlight method.
From what I've seen, you can use it instead of .Execute in a Find.

But I don't have Word2007 installed and can't test how/if it works...
Not even sure whether "highlight" means "select", or if it's just redundant
for ".Find.Highlight=True".

Regards,
Klaus

> Hi Igor
>
[quoted text clipped - 6 lines]
> Shauna Kelly.  Microsoft MVP.
> http://www.shaunakelly.com/word
Igor - 25 Jun 2007 07:27 GMT
Thanks !
It works fine !

I'm also currently working with Office2003.

> Word 2007 has a new .HitHighlight method.
> From what I've seen, you can use it instead of .Execute in a Find.
[quoted text clipped - 16 lines]
> > Shauna Kelly.  Microsoft MVP.
> > http://www.shaunakelly.com/word
Helmut Weber - 22 Jun 2007 14:13 GMT
Hi Igor,

I usually recommend to use highlighting
as a substitute for a multiple selection.

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

' now you can do whatever you want with the highliohted text.

Sub RemoveHighLight()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
  .Text = ""
  .Highlight = True
  While .Execute
     If rDcm.HighlightColorIndex = wdYellow Then
        ' your code
        rDcm.HighlightColorIndex = wdNoHighlight
        rDcm.Collapse Direction:=wdCollapseEnd
        rDcm.End = ActiveDocument.Range.End
     End If
  Wend
End With
End Sub

In theory, there are limits,
if your doc contains all possible kinds of hightlighting.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Igor - 22 Jun 2007 14:34 GMT
Thanks !

It is exactly what I'm looking for !

> Hi Igor,
>
[quoted text clipped - 33 lines]
> In theory, there are limits,
> if your doc contains all possible kinds of hightlighting.
Igor - 25 Jun 2007 07:23 GMT
I made as you offered and it works fine. But I have another problem.

I opened document not directly, but in Visual Basic 6.0 WebBrowser control.
When I selected any text the Saved property of the document did not change,
but when I highlighting even one character, I cannot prevent the WebControl
from displaying save message. Undo method also has no effect.
Even if I set oWebControl.Document.Saved = true, the message displayed
anyway and WebControl performs save on Yes button. The same trick works well
if I open Excel document.

How can I force WebControl not to save Word document.

Thanks!

> Hi Igor,
>
[quoted text clipped - 33 lines]
> In theory, there are limits,
> if your doc contains all possible kinds of hightlighting.
 
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.