View Single Post
 
Old 11-07-2023, 12:22 PM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Vivka,


I don't know if any of us here are professionals or if any of us have stopped learning from others. RobiNew, Vivka status flag is based solely on post count.


I looked at the code you posted Vivka and have the following comments/suggestions:
-I try to avoid GoTo
-While what you posted seems to work for the OP, it seems that if a one line paragraph was nested with other one line paragraphs (not the first) then the OP stated conditions were not handled.
-Rest of comments are inline with the code.


Code:
Sub OneLinersII()
'In selection, replace Chr(13) with Chr(11) between all
'consecutive one-line paras, if....
Dim oPar As Paragraph 'If you dim one variable, why don't you dim all variables?
Dim oRng As Range 'You declared the range object as a variant.  Why not as a range?
  Application.ScreenUpdating = False
  Set oRng = ActiveDocument.Range
  For Each oPar In oRng.Paragraphs
    If oPar.Range.End >= oRng.End Then Exit For 'If you Exit Sub then you won't execute your ScreenUpdating line
    If Not oPar.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter _
      And Not oPar.Range Like "*[0-9]*" Then
      If oPar.Range.ComputeStatistics(wdStatisticLines) = 1 Then
        Do While oPar.Next.Range.ComputeStatistics(wdStatisticLines) = 1 _
          And Not oPar.Range.Next.ParagraphFormat.Alignment = wdAlignParagraphCenter _
          And Not oPar.Next.Range Like "*[0-9]*"
          oPar.Range.Characters.Last.Text = Chr(11)
        Loop
      End If
    End If
  Next oPar
  Application.ScreenUpdating = True
  Set oRng = Nothing: Set oPar = Nothing
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by gmaxey; 11-08-2023 at 04:32 AM.
Reply With Quote