View Single Post
 
Old 11-27-2020, 07:11 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
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