Conditionally deleting paragraph borders

N

Neil Humphries

I need to delete specific paragraph borders in a document and leave all
others including those in tables alone. The ones I want to delete occur in
paragraphs with only right borders. They are the minority of paragraphs in
the document.

I think the code below expresses the logic, unfortunately it doesn't do
anything. I expect that I am not creating a valid selection. Any help will be
appreciated.

I am using Word 2007 SP1 on Win XP Pro 64.

Sub DeleteParaBorder()
Dim oPrg As Paragraph
For Each oPrg In ActiveDocument.Paragraphs
'check if there is a right border
If Selection.ParagraphFormat.Borders(wdBorderRight).LineStyle =
wdLineStyleSingle Then
'check that there is no left border
If Selection.ParagraphFormat.Borders(wdBorderLeft).LineStyle =
wdLineStyleNone Then
'check that there are no shadows
If Selection.ParagraphFormat.Borders.Shadow = False Then
'set the right border to none
Selection.ParagraphFormat.Borders(wdBorderRight).LineStyle =
wdLineStyleNone
End If
End If
End If
Next
 
P

Pesach Shelnitz

Hi Neil,

You almost had it. You just need to change Selection to oPrg.Range, as in
the following.

Sub DeleteParaBorder()
Dim oPrg As Paragraph
For Each oPrg In ActiveDocument.Paragraphs
'check if there is a right border
If oPrg.Range.ParagraphFormat.Borders(wdBorderRight).LineStyle = _
wdLineStyleSingle Then
'check that there is no left border
If oPrg.Range.ParagraphFormat.Borders(wdBorderLeft).LineStyle = _
wdLineStyleNone Then
'check that there are no shadows
If oPrg.Range.ParagraphFormat.Borders.Shadow = False Then
'set the right border to none
oPrg.Range.ParagraphFormat.Borders(wdBorderRight).LineStyle = _
wdLineStyleNone
End If
End If
End If
Next
End Sub
 

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