Selecting Multiple Words

S

sos00

Hi,

is it possible to select multiple words in a word document at once ?
for example i want to select and highlight "word1" and "word2" in this text
:

word0 word1 word
word word2 word3

Thanks
 
C

Cindy M -WordMVP-

Hi Sos00,
is it possible to select multiple words in a word document at once ?
for example i want to select and highlight "word1" and "word2" in this text
:

word0 word1 word
word word2 word3
In word 2002 and 2003, in the user interface, yes: select the first word, then
hold Ctrl and select the next, and so on.

This functionality is NOT available through the Word object model (VBA),
however. The only part of this functionality supported in the object model is
selecting all text that's formatted the same as the current selection:

WordBasic.SelectSimilarFormatting

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
D

Doug Robbins - Word MVP

Hold down the control key as you select the second and any subsequent words.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

sos00

Thanks,
is it possible to use Find to do this ?
is Find capable to find multiple words at once ?
 
H

Helmut Weber

Hi,

you may create your own find and highlight code.
Still, all find action is serial, in a way, as there is
no straightforward search doing all at once.

Have a look at this simple example:

Sub MyFind()
Dim l As Long
Dim rDcm As Range
Dim sTmp() As String
sTmp = Split(InputBox("Myfind"), " ")

For l = 0 To UBound(sTmp)
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = sTmp(l)
While .Execute
rDcm.HighlightColorIndex = wdYellow
Wend
End With
Next
End Sub

Note that the delimiter is " ".

You may add all kinds of features you can think of.

In the inputbox, type something like: "brown fox jumps",
without the quotation marks.

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
C

Cindy M -WordMVP-

Hi Sos00,
is it possible to use Find to do this ?
is Find capable to find multiple words at once ?
Not if they're not contiguous. Again, the user interface
supports this, but the object model does not.

The way you have things lined up in your original
question... Could this be in a table? You can select a
table column.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
D

Doug Robbins - Word MVP

In your original post, the assumption was that Word1 and Word2 might be in
cells in the same column in a table.

You can select multiple contiguous rows or columns in a table, but there is
no way using vba to select anything that is NOT contiguous.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top