Auto word highlighting

M

Mike

From my own Windows application, I want to launch Word and pass it a word,
say it is "computer". I am looking for a way to have Word display the file
I tell it to, and automatically highlight the word "computer" everywhere in
that document (with whatever color).

Is this doable?
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Mike,

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="computer", Wrap:=wdFindStop,
Forward:=True) = True
Selection.Range.Shading.BackgroundPatternColorIndex = wdYellow
Loop
End With

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
U

Ulf Nilsson

Is it doable in textboxes?

/ Ulf

-----Original Message-----
Hi Mike,

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="computer", Wrap:=wdFindStop,
Forward:=True) = True
Selection.Range.Shading.BackgroundPatternColorIndex =
wdYellow
 
M

Mike

Thanks Doug! I have several hurdles to cross before I can test this (such
as how to invoke Word and pass a word to the macro from my own COM program),
but I will follow up here for the benefit of others.

"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
 
U

Ulf Nilsson

Hi Jay
I have read the article and it is useful, but I want to
highlight words in a textbox in a dialogue box, not in
the document. Is that doable?

/ Ulf
 
J

Jonathan West

Ulf Nilsson said:
Hi Jay
I have read the article and it is useful, but I want to
highlight words in a textbox in a dialogue box, not in
the document. Is that doable?

Textboxes on userforms in VBA can only contain simple text. It isn't
possuble to apply separate formatting to individual words.

it might be possible to make use of a Rich Text control from a different
company and add that to a userform.
 

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