Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 11-27-2020, 07:11 AM
gmaxey gmaxey is offline I need a macro to move dangling words to a new line please Windows 10 I need a macro to move dangling words to a new line please Office 2016
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

For something like your specific example where it appears that you have running text this "MIGHT" work fundamentally. The document needs to be in print layout view. Basically, it loops through the Page, Rectangle and Line objects and sees "." " " and "This" as the Previous.Previous, Previous and Last word of the line. In that condition, the Previoius word (or the space between the "." and This) is replaced with a line break forcing "This" to the next line."

Code:
Sub LoopByLine()
Dim oPage As Page
Dim lngRec As Long, lngLine As Long
Dim oRng As Word.Range
  For Each oPage In ActiveDocument.ActiveWindow.ActivePane.Pages
    For lngRec = 1 To oPage.Rectangles.Count
      For lngLine = 1 To oPage.Rectangles(lngRec).Lines.Count
        Set oRng = oPage.Rectangles(lngRec).Lines(lngLine).Range
        If oRng.Words.Last.Previous.Previous = "." Then
          oRng.Words.Last.Previous = Chr(11)
        End If
        Application.ScreenRefresh
      Next lngLine
    Next lngRec
  Next oPage
lbl_Exit:
  Exit Sub
End Sub

However, in practice and considering that the result you see on your PC could be vastly different than what I would see on my PC, it is probably a futile exercise. Whatever you do, save and publish as a PDF file before distribution.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to move a line to another line that starts with a chain selected in the 1st one? gloub Word VBA 24 03-19-2019 03:12 PM
I need a macro to move dangling words to a new line please Capitalize one to two words if they are the only words on a line jrhlavac Word VBA 1 10-08-2015 08:19 PM
I need a macro to move dangling words to a new line please macro to add brackets to each line and add single quotes to each word in the line bracketandquotes Word VBA 17 02-16-2015 03:51 PM
Lock line so text does not move to next line saundrals Word 2 06-19-2014 03:59 PM
I need a macro to move dangling words to a new line please Identify certain text and move all phrases containing it down a line Chayes Word VBA 2 11-26-2013 01:16 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:40 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