#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
You don't need a macro for this - just a wildcard Find/Replace, where:
Find = (Alfa)*(Brava) Replace = \1 \2
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Delete Text from Insertion Point to Found Text | feenyman99 | Word | 0 | 04-17-2016 05:40 PM |
Microsoft Word macro to find text, select all text between brackets, and delete | helal1990 | Word VBA | 4 | 02-05-2015 03:52 PM |
How to find and delete duplicate words in doc | cinvest | Word | 1 | 09-29-2014 08:34 PM |
Words are being duplicated in text boxes | argentraven | PowerPoint | 0 | 07-24-2014 03:10 PM |
Remove text between two words | VeeCee | Word VBA | 7 | 01-05-2014 03:39 PM |