Paragraph alignment in a macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everybody,
I'm trying to write a macro, and one of the first steps I want is to delete
any text that is center-aligned. I tried to record a macro, using the find
and replace, but then when I ran the macro I couldn't make it work. I don't
know much about writing macro code, does anybody know how to put this into a
macro? I only need a little snippet of code, if you can.
Thanks!
jezzica85
 
Dim i As Long

With ActiveDocument
For i = .Paragraphs.Count To 1 Step -1
If .Paragraphs(i).Alignment = wdAlignParagraphCenter Then
.Paragraphs(i).Range.Delete
End If
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
Hi Jezzica,

Sub Test345()
Dim rDcm As Range
Dim rPrg As Paragraph
Set rDcm = ActiveDocument.Range
For Each rPrg In rDcm.Paragraphs
If rPrg.Alignment = wdAlignParagraphCenter Then
rPrg.Range.Delete
End If
Next
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
Back
Top