Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Sun, 16 Mar 2008 15:11:44 -0700,    group: microsoft.public.word.vba.beginners        back       


Trying to create a macro to change case on one style   
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
date: Sun, 16 Mar 2008 15:11:44 -0700   author:   Barbara

Re: Trying to create a macro to change case on one style   
On Sun, 16 Mar 2008 15:11:44 -0700, Barbara  wrote:

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

--
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: Sun, 16 Mar 2008 20:36:26 -0400   author:   Jay Freedman

Re: Trying to create a macro to change case on one style   
On 3/16/2008 5:36 PM Pacific Time, Jay Freedman wrote thusly:
> On Sun, 16 Mar 2008 15:11:44 -0700, Barbara  wrote:
> 
>> 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).
> 
> --
> 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.


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
date: Sun, 16 Mar 2008 18:46:32 -0700   author:   Barbara

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us