|
|
Find and replace text thats not wdAlignParagraphCenter alignment
Im trying to make a macro that set alignment on all text to
wdAlignParagraphJustify, except text that is wdAlignParagraphCenter.
Right now i have this:
With ActiveDocument.Content.Find
.ClearFormatting
.ParagraphFormat.Alignment = wdAlignParagraphRight
With .Replacement
.ClearFormatting
.ParagraphFormat.Alignment = wdAlignParagraphJustify
End With
.Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content.Find
.ClearFormatting
.ParagraphFormat.Alignment = wdAlignParagraphLeft
With .Replacement
.ClearFormatting
.ParagraphFormat.Alignment = wdAlignParagraphJustify
End With
.Execute Replace:=wdReplaceAll
End With
This works, but I was hoping for a better solution since there apparently
exists alot more alignment constants then those two.
ActiveDocument.Content.Find.ParagraphFormat.Alignment <>
wdAlignParagraphCenter
doesnt work.
/Niels
|
|
0
|
|
|
|
Reply
|
Utf
|
5/25/2010 11:59:01 AM |
|
How about
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Range.Paragraphs
If oPara.Alignment <> wdAlignParagraphCenter Then
oPara.Alignment = wdAlignParagraphJustify
End If
Next oPara
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
"Tilds" <Tilds@discussions.microsoft.com> wrote in message
news:744517F6-EAA4-47DF-A9E9-10D7B16EC9C6@microsoft.com...
>
> Im trying to make a macro that set alignment on all text to
> wdAlignParagraphJustify, except text that is wdAlignParagraphCenter.
>
> Right now i have this:
> With ActiveDocument.Content.Find
> .ClearFormatting
> .ParagraphFormat.Alignment = wdAlignParagraphRight
> With .Replacement
> .ClearFormatting
> .ParagraphFormat.Alignment = wdAlignParagraphJustify
> End With
> .Execute Replace:=wdReplaceAll
> End With
> With ActiveDocument.Content.Find
> .ClearFormatting
> .ParagraphFormat.Alignment = wdAlignParagraphLeft
> With .Replacement
> .ClearFormatting
> .ParagraphFormat.Alignment = wdAlignParagraphJustify
> End With
> .Execute Replace:=wdReplaceAll
> End With
>
> This works, but I was hoping for a better solution since there apparently
> exists alot more alignment constants then those two.
> ActiveDocument.Content.Find.ParagraphFormat.Alignment <>
> wdAlignParagraphCenter
> doesnt work.
>
> /Niels
|
|
0
|
|
|
|
Reply
|
Graham
|
5/25/2010 12:53:19 PM
|
|
On further reflection it will probably be necessary to refresh the screen to
show the changes immediately, thus
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Range.Paragraphs
If oPara.Alignment <> wdAlignParagraphCenter Then
oPara.Alignment = wdAlignParagraphJustify
End If
Next oPara
Application.ScreenRefresh
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
"Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message
news:htgh7m$6vl$1@news.eternal-september.org...
> How about
>
> Dim oPara As Paragraph
> For Each oPara In ActiveDocument.Range.Paragraphs
> If oPara.Alignment <> wdAlignParagraphCenter Then
> oPara.Alignment = wdAlignParagraphJustify
> End If
> Next oPara
>
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
>
> "Tilds" <Tilds@discussions.microsoft.com> wrote in message
> news:744517F6-EAA4-47DF-A9E9-10D7B16EC9C6@microsoft.com...
>>
>> Im trying to make a macro that set alignment on all text to
>> wdAlignParagraphJustify, except text that is wdAlignParagraphCenter.
>>
>> Right now i have this:
>> With ActiveDocument.Content.Find
>> .ClearFormatting
>> .ParagraphFormat.Alignment = wdAlignParagraphRight
>> With .Replacement
>> .ClearFormatting
>> .ParagraphFormat.Alignment = wdAlignParagraphJustify
>> End With
>> .Execute Replace:=wdReplaceAll
>> End With
>> With ActiveDocument.Content.Find
>> .ClearFormatting
>> .ParagraphFormat.Alignment = wdAlignParagraphLeft
>> With .Replacement
>> .ClearFormatting
>> .ParagraphFormat.Alignment = wdAlignParagraphJustify
>> End With
>> .Execute Replace:=wdReplaceAll
>> End With
>>
>> This works, but I was hoping for a better solution since there apparently
>> exists alot more alignment constants then those two.
>> ActiveDocument.Content.Find.ParagraphFormat.Alignment <>
>> wdAlignParagraphCenter
>> doesnt work.
>>
>> /Niels
>
>
|
|
0
|
|
|
|
Reply
|
Graham
|
5/25/2010 1:02:38 PM
|
|
That works great! ScreenRefresh wasn't even necessary.
Thank you very much, now it should work for all alignments.
/Niels
"Graham Mayor" wrote:
> On further reflection it will probably be necessary to refresh the screen to
> show the changes immediately, thus
>
> Dim oPara As Paragraph
> For Each oPara In ActiveDocument.Range.Paragraphs
> If oPara.Alignment <> wdAlignParagraphCenter Then
> oPara.Alignment = wdAlignParagraphJustify
> End If
> Next oPara
> Application.ScreenRefresh
>
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message
> news:htgh7m$6vl$1@news.eternal-september.org...
> > How about
> >
> > Dim oPara As Paragraph
> > For Each oPara In ActiveDocument.Range.Paragraphs
> > If oPara.Alignment <> wdAlignParagraphCenter Then
> > oPara.Alignment = wdAlignParagraphJustify
> > End If
> > Next oPara
> >
> >
> > --
> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> > Graham Mayor - Word MVP
> >
> > My web site www.gmayor.com
> > Word MVP web site http://word.mvps.org
> > <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> >
> >
> >
> > "Tilds" <Tilds@discussions.microsoft.com> wrote in message
> > news:744517F6-EAA4-47DF-A9E9-10D7B16EC9C6@microsoft.com...
> >>
> >> Im trying to make a macro that set alignment on all text to
> >> wdAlignParagraphJustify, except text that is wdAlignParagraphCenter.
> >>
> >> Right now i have this:
> >> With ActiveDocument.Content.Find
> >> .ClearFormatting
> >> .ParagraphFormat.Alignment = wdAlignParagraphRight
> >> With .Replacement
> >> .ClearFormatting
> >> .ParagraphFormat.Alignment = wdAlignParagraphJustify
> >> End With
> >> .Execute Replace:=wdReplaceAll
> >> End With
> >> With ActiveDocument.Content.Find
> >> .ClearFormatting
> >> .ParagraphFormat.Alignment = wdAlignParagraphLeft
> >> With .Replacement
> >> .ClearFormatting
> >> .ParagraphFormat.Alignment = wdAlignParagraphJustify
> >> End With
> >> .Execute Replace:=wdReplaceAll
> >> End With
> >>
> >> This works, but I was hoping for a better solution since there apparently
> >> exists alot more alignment constants then those two.
> >> ActiveDocument.Content.Find.ParagraphFormat.Alignment <>
> >> wdAlignParagraphCenter
> >> doesnt work.
> >>
> >> /Niels
> >
> >
>
>
> .
>
|
|
0
|
|
|
|
Reply
|
Utf
|
5/25/2010 2:03:01 PM
|
|
|
3 Replies
660 Views
(page loaded in 0.08 seconds)
|
|
|
|
|
|
|
|
|