View Single Post
 
Old 10-06-2020, 10:53 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,103
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

Please use the # to add code tags when posting code.
Both the code I posted and Andrew's Cancel addition will delete autonumbered texts, if those sentences complete a paragraph. If they don't then you will also need to remove the numbering e.g
Code:
Sub Delete_Sentence_if_Word_found()
Dim strTexts As String, oRng As Range, iResponse As Integer
    strTexts = InputBox("Enter texts to be found here: ", , "continued")
    Set oRng = ActiveDocument.Range
    With oRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        While .Execute(findText:=strTexts)
            oRng.Expand Unit:=wdSentence
            oRng.Select
            ActiveDocument.ActiveWindow.ScrollIntoView oRng, True
            iResponse = MsgBox("Are you sure to delete the sentence?", vbYesNoCancel)
            If iResponse = vbYes Then
                oRng.Text = ""
                oRng.ListFormat.RemoveNumbers
            ElseIf iResponse = vbCancel Then
                Exit Sub
            End If
            oRng.Collapse wdCollapseEnd
        Wend
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub

Without knowing what is in the paragraphs you can only program on the basis of what you do know.
__________________
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