|
|
|
date: Tue, 27 May 2008 03:40:00 -0700,
group: microsoft.public.word.vba.beginners
back
Re: Selecting a word then applying bold format
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
"Jay Freedman" wrote:
> dy29832 wrote:
> > 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 FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so
> all may benefit.
>
>
>
date: Tue, 27 May 2008 10:28:01 -0700
author: dy29832
Re: Selecting a word then applying bold format
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
"Jean-Guy Marcil" wrote:
> "dy29832" wrote:
>
> > 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
date: Tue, 27 May 2008 16:34:00 -0700
author: dy29832
Re: Selecting a word then applying bold format
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
"dy29832" wrote in message
news:22FC8057-ABCB-4D7A-8D7C-CF621F61E694@microsoft.com...
> 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
>
> "Jean-Guy Marcil" wrote:
>
>> "dy29832" wrote:
>>
>> > 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
date: Wed, 28 May 2008 13:06:39 +1000
author: Doug Robbins - Word MVP
|
|