View Single Post
 
Old 10-06-2020, 09:23 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

And to include a Cancel option by building on to Graham's code
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: ")
  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 = ""
      ElseIf iResponse = vbCancel Then
        Exit Sub
      End If
      oRng.Collapse wdCollapseEnd
    Wend
  End With
lbl_Exit:
  Set oRng = Nothing
  Exit Sub
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote