View Single Post
 
Old 03-06-2020, 01:49 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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 ofgmayor has much to be proud of
Default

What do you want to do with the two split parts of the paragraph? The following has added code to insert a paragraph break after 50 words
Code:
Sub DeleteTextBetweenTwoWords()
Dim strFirstWord As String
Dim strLastWord As String
Dim objDoc As Document
Dim lngPara As Long
Dim oRng As Range

    Set objDoc = ActiveDocument
    strFirstWord = "T:"
    strLastWord = "P:"

    With Selection
        .HomeKey Unit:=wdStory
        With Selection.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = strFirstWord & "*" & strLastWord
            .Replacement.Text = strLastWord
            .MatchWildcards = True
            .Execute Replace:=wdReplaceAll
        End With
    End With

    For lngPara = objDoc.Paragraphs.Count To 1 Step -1
        Set oRng = objDoc.Paragraphs(lngPara).Range
        If oRng.Words.Count > 50 Then
            oRng.MoveStart wdWord, 50
            oRng.Collapse 1
            oRng.InsertParagraphAfter
        End If
    Next lngPara

    Set objDoc = Nothing
    Set oRng = Nothing
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