Answers for "how to delete content in word between two strings"

0

how to delete content in word between two strings

Sub DeleteTextBetweenTwoWords()
  Dim strFirstWord As String
  Dim strLastWord As String
  Dim objDoc As Document
  Dim objWord As Object
 
  Set objDoc = ActiveDocument
  strFirstWord = InputBox("Enter the first word:", "First Word")
  strLastWord = InputBox("Enter the last word:", "Last Word")
 
  With Selection
    .HomeKey Unit:=wdStory
    With Selection.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = strFirstWord & "*" & strLastWord
      .Replacement.Text = strFirstWord & strLastWord
      .MatchWildcards = True
      .Execute Replace:=wdReplaceAll
    End With
  End With
 
  Set objDoc = Nothing
  Set objWord = Nothing
End Sub
Posted by: Guest on October-01-2021

Code answers related to "how to delete content in word between two strings"

Browse Popular Code Answers by Language