Tuesday, June 7, 2011

Delete All Paragraphs This Style

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
End If
Next lng
End Sub

No comments:

Post a Comment