Trying to create a macro to change case on one style

B

Barbara

I have Word 2000 and have limited experience in writing macros (though I
was a computer programmer many years ago, so understand logic).

I have a large document (300+ pages) with question/answer type things
all the way through the document. I have it now with 2 styles in my
document: DefaultText (for the questions) and ABC style (for the answers).

In the ABC style, most of the answer text is in all CAPS, though not all
of it. It's a bit hard to read.

My goal: to create a macro to change all of the paragraphs marked with
ABC style to Sentence Case. I tried creating a macro by recording but I
can't figure out how to have the macro do a find of each paragraph and
then apply the change case. Case isn't one of the regular attribute of
styles so changing the style doesn't seem to help me.
Can anyone help? I very much appreciate it in advance. Thanks :)


Barbara
 
J

Jay Freedman

I have Word 2000 and have limited experience in writing macros (though I
was a computer programmer many years ago, so understand logic).

I have a large document (300+ pages) with question/answer type things
all the way through the document. I have it now with 2 styles in my
document: DefaultText (for the questions) and ABC style (for the answers).

In the ABC style, most of the answer text is in all CAPS, though not all
of it. It's a bit hard to read.

My goal: to create a macro to change all of the paragraphs marked with
ABC style to Sentence Case. I tried creating a macro by recording but I
can't figure out how to have the macro do a find of each paragraph and
then apply the change case. Case isn't one of the regular attribute of
styles so changing the style doesn't seem to help me.
Can anyone help? I very much appreciate it in advance. Thanks :)


Barbara

This is one of many things in Word that can't be created with the recorder.

The general idea is to set up a Find that locates a paragraph with the ABC
style, and make that Find repeat until there aren't any more (this is the
purpose of the Do While .Execute ... Loop construction). Each time a paragraph
is found, the text in it is changed to Sentence case.

Sub demo()
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Text = ""
.Format = True
.Style = ActiveDocument.Styles("ABC")
.Forward = True
.Wrap = wdFindStop
Do While .Execute
oRg.Case = wdTitleSentence
Loop
End With
End Sub

The .Format = True tells VBA to use the .Style as one of the Find criteria (in
fact, since the .Text is empty, the .Style is the only criterion).
 
B

Barbara

This is one of many things in Word that can't be created with the recorder.

The general idea is to set up a Find that locates a paragraph with the ABC
style, and make that Find repeat until there aren't any more (this is the
purpose of the Do While .Execute ... Loop construction). Each time a paragraph
is found, the text in it is changed to Sentence case.

Sub demo()
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Text = ""
.Format = True
.Style = ActiveDocument.Styles("ABC")
.Forward = True
.Wrap = wdFindStop
Do While .Execute
oRg.Case = wdTitleSentence
Loop
End With
End Sub

The .Format = True tells VBA to use the .Style as one of the Find criteria (in
fact, since the .Text is empty, the .Style is the only criterion).

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


Jay,
Outstanding!!!! That worked very fast. You made my day and saved me
many hours of tedious work. :):):) Many blessings upon you.

Irish Blessing

Bless you and yours
As well as the cottage you live in.
May the roof overhead be well thatched
And those inside be well matched.

An Irish Friendship Wish

May there always be work for your hands to do
May your purse always hold a coin or two
May the sun always shine on your windowpane
May a rainbow be certain to follow each rain
May the hand of a friend always be near you
May God fill your heart with gladness to cheer you.


Barbara
 

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