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"
 

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

Similar Threads

Find and replace question 2
Find and replace followup 3
alignment macro 5
Alignment problem 1
Macro help 1
Two more macro questions 6
Can paragraph alignment be turned off? 9
Finding all paragraphs with quotes 10

Back
Top