Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-27-2020, 06:26 AM
iNeedaMacroPlease iNeedaMacroPlease is offline I need a macro to move dangling words to a new line please Mac OS X I need a macro to move dangling words to a new line please Office 2016
Novice
I need a macro to move dangling words to a new line please
 
Join Date: Nov 2020
Posts: 1
iNeedaMacroPlease is on a distinguished road
Question I need a macro to move dangling words to a new line please


Problem

I would like to use a macro to check a document in full and identify dangling words at the end of a line, e.g:

This is an example of the dangling word problem. This
is the dangling word.

And move the dangling word to the next line, e.g:

This is an example of the dangling word problem.
This is the dangling word.

TIA
Reply With Quote
  #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,421
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
  #3  
Old 11-27-2020, 11:34 AM
macropod's Avatar
macropod macropod 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 2010
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

One might approach it via a wildcard Find/Replace, where:
Find = ([.:;\!\?] <*>)^32
Replace = \1^s
This way, the 'dangling word' problem will be resolved for whatever system the document is viewed on, even if the page layout changes. No code required.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


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 10:39 AM.


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