View Single Post
 
Old 01-12-2018, 02:48 AM
warddegeest warddegeest is offline Windows 10 Office 2016
Novice
 
Join Date: Jan 2018
Posts: 1
warddegeest is on a distinguished road
Default Using VBA to delete text between two words

I have a text, and I want to delete the text between the words "Alfa" and "Brava".

I tried something as this, it displayes the text between, but does not delete this.


Dim rng1 As Range
Dim rng2 As Range
Dim strTheText As String
Set rng1 = ActiveDocument.Range
If rng1.Find.Execute(FindText:="Alfa") Then
Set rng2 = ActiveDocument.Range(rng1.End, ActiveDocument.Range.End)
If rng2.Find.Execute(FindText:="Brava") Then
strTheText = ActiveDocument.Range(rng1.End, rng2.Start).Text
MsgBox strTheText
End If

Any help would be appreciated.

Ward
Reply With Quote