Selecting a word then applying bold format

D

dy29832

I'm having trouble selecting a particular word and then applying the bold
format to it. Does anyone have some example code to get me started.

Thanks in advance,

dy29832
 
J

Jay Freedman

dy29832 said:
I'm having trouble selecting a particular word and then applying the
bold format to it. Does anyone have some example code to get me
started.

Thanks in advance,

dy29832

Is the "particular word" already in the document, or is it being inserted by
your code? If it already exists, and it's in more than one place, do you
want to apply bold to all occurrences or just one (and if just one, how
should the macro recognize which is the "right" one)?

The techniques are different, depending on the answers to these questions.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
D

dy29832

Thanks for the response,

The word I am selecting is already in the document, but does not have the
bold format applied to it yet.

The word I would like to bold could possibly show up in the text later, but
I only want to bold this particular word because it is a heading.

I'm not sure if a macro can be written to recognize a heading versus text in
the body of a paragraph, but that would be a nice extra. Otherwise, I could
simply review my document and "unbold" the instances that were performed
incorrectly.

Thanks again,

David Yale
 
J

Jean-Guy Marcil

dy29832 said:
Thanks for the response,

The word I am selecting is already in the document, but does not have the
bold format applied to it yet.

The word I would like to bold could possibly show up in the text later, but
I only want to bold this particular word because it is a heading.

I'm not sure if a macro can be written to recognize a heading versus text in
the body of a paragraph, but that would be a nice extra. Otherwise, I could
simply review my document and "unbold" the instances that were performed
incorrectly.

So, you want to bold all instances of a particular word that appears in
heading pargraphs?
Are those headings formatted with a style?
Have you tried recording a macro?

See
http://word.mvps.org/faqs/macrosvba/UsingRecorder.htm
and
http://word.mvps.org/faqs/macrosvba/ModifyRecordedMacro.htm
 
D

dy29832

The headings are the same style as all the other text in the paragraph.
I have tried recording a macro and I don't see where the bold statement is
located.
Here is the sub routine.

Sub Soapnote()
'
' Soapnote Macro
' Macro recorded 5/27/2008 by David Yale
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "REVIEW OF SYSTEMS"
.Replacement.Text = "REVIEW OF SYSTEMS"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.CorrectHangulEndings = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
End Sub


I use a Ctrl-H command to find and replace the text, then select format and
the bold selection. It does bold REVIEW OF SYSTEMS, but I can't figure out
how it does it in the routine.

Thanks,

David Yale
 
D

Doug Robbins - Word MVP

Use:

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(Findtext:="REVIEW OF SYSTEMS", Forward:=True,
_
MatchCase:=True, MatchWildcards:=False, Wrap:=wdFindStop) =
True
Selection.Range.Font.Bold = True
Loop
End With

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