![]() |
|
#4
|
|||
|
|||
|
I think you are adding more bells and whistles than your really need. There is really no need to evaluate every paragraph. Perhaps something like:
Code:
Sub DeleteEmptyParagraphs()
Dim oRng As Range
Dim lngST As Long, lngCount As Long, lngIndex As Long
Dim oPar As Paragraph
lngST = Timer
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = Chr(13) & "{2,}"
.MatchWildcards = True
While .Execute
For lngIndex = oRng.Paragraphs.Count To 1 Step -1
Set oPar = oRng.Paragraphs(lngIndex)
If Len(oPar.Range.Text) = 1 Then
oPar.Range.Select
Select Case AscW(oPar.Range.Characters.Last.Next)
Case 12 'Do nothing
Case Else
oPar.Range.Delete
lngCount = lngCount + 1
End Select
End If
Next lngIndex
oRng.Collapse wdCollapseEnd
Wend
End With
MsgBox "Paragraphs deleted: " & lngCount & " | Execution time: " & _
Round(Timer - lngST, 2) & " s | " & Format((Timer - lngST) / 60, "0.00") & " min"
lbl_Exit:
Exit Sub
End Sub
|
| Tags |
| content control, delete empty, paragraphs |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Remove extra space before a paragraph and return it to previous paragraph
|
laith93 | Word VBA | 7 | 04-27-2022 08:26 AM |
| a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection | drrr | Word VBA | 2 | 08-24-2021 03:05 AM |
| Inserting text from a Userform into a Field in a paragraph in a paragraph in a word document | storemaz | Word VBA | 1 | 03-13-2020 08:11 AM |
Continuous Paragraph across two columns vs Parallel Column Paragraph
|
Pinesh | Word | 2 | 03-09-2018 04:24 PM |
Cross-reference to paragraph not updating when paragraph moves
|
windhoek2010 | Word | 1 | 09-15-2017 08:30 PM |