Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-07-2023, 12:22 PM
gmaxey gmaxey is offline Find and format lines of verse Windows 10 Find and format lines of verse Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Format Word Document - Remove timestamps on individual lines lbeck Word 4 06-21-2023 12:47 PM
How do I format indented bulleted lines??? HELP PLEASE!!! nicholeproffitt Word 1 02-05-2015 05:42 PM
Find and format lines of verse Print table and on verse form vba LaercioNB Excel 1 08-09-2013 06:03 PM
How to remove unwanted lines - I cannot even find how/where they are inserted! nickib Word 7 08-09-2013 06:01 AM
Find and format lines of verse Find and Replace multiple lines/paragraphs jcw Word 1 11-18-2011 11:47 AM

Other Forums: Access Forums

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


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