Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 12-06-2024, 01:38 PM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 

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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft