View Single Post
 
Old 10-28-2018, 05:17 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following macro will find the next paragraph that begins with the selected text and will insert the paragraph that contains the selected text before it. It assumes that at least two words are selected. You can change that as appropriate. http://www.gmayor.com/installing_macro.htm

Code:
Sub Macro1()
'Graham Mayor - http://www.gmayor.com - Last updated - 28 Oct 2018 

 Dim oRng As Range, oSel As Range
    Set oSel = Selection.Range
    If oSel.Words.Count > 2 Then
        Set oRng = ActiveDocument.Range
        oRng.Start = oSel.Paragraphs(1).Range.End
        With oRng.Find
            Do While .Execute(oSel)
                If oRng.Start = oRng.Paragraphs(1).Range.Start Then
                    oRng.Collapse 1
                    oRng.FormattedText = oSel.Paragraphs(1).Range.FormattedText
                    oSel.Paragraphs(1).Range.Delete
                    Exit Do
                End If
                oRng.Collapse 0
            Loop
        End With
    End If
lbl_Exit:
    Set oRng = Nothing
    Set oSel = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote