709-218-7927

The Landfall Garden House

60 Canon Bayley Road

Bonavista, Newfoundland

CANADA A0C 1B0

CPRGreaves@gmail.com

Home

Christopher Greaves

Delete All Paragraphs This Style

Tuesday, June 7, 2011

From time to time I have occasion to remove globs of text from a document leaving bits behind.

For example, I might want to delete all “Normal" styled paragraphs and leave only the 'Heading " styled paragraphs behind.

This macro does the trick, regardless of the styles in use!

Sub DeleteAllParagraphsThisStyle()

''' Place the text cursor in a paragraph, run the macro.

''' All paragraphs in that (selected) style will be removed from the document.

Dim strStyleName As String

strStyleName = Selection.Paragraphs(1).Range.Style

Dim lng As Long

For lng = ActiveDocument.Paragraphs.Count To 1 Step -1

If ActiveDocument.Paragraphs(lng).Style = strStyleName Then

ActiveDocument.Paragraphs(lng).Range.Delete

Else

End If

Next lng

End Sub

709-218-7927 CPRGreaves@gmail.com

Bonavista, Sunday, December 08, 2024 9:33 AM

Copyright © 1990-2024 Chris Greaves. All Rights Reserved.