Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Trying to create a macro to change case on one style

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Barbara - 16 Mar 2008 23:11 GMT
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
Jay Freedman - 17 Mar 2008 01:36 GMT
>I have Word 2000 and have limited experience in writing macros (though I
>was a computer programmer many years ago, so understand logic).
[quoted text clipped - 14 lines]
>
>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        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
Barbara - 17 Mar 2008 02:46 GMT
On 3/16/2008 5:36 PM Pacific Time, Jay Freedman wrote thusly:

>> I have Word 2000 and have limited experience in writing macros (though I
>> was a computer programmer many years ago, so understand logic).
[quoted text clipped - 46 lines]
> Microsoft Word MVP        FAQ: http://word.mvps.org
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.