Find and replace text thats not wdAlignParagraphCenter alignment

T

Tilds

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
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Tilds

That works great! ScreenRefresh wasn't even necessary.
Thank you very much, now it should work for all alignments.

/Niels
 

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