Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-12-2018, 02:48 AM
warddegeest warddegeest is offline Using VBA to delete text between two words Windows 10 Using VBA to delete text between two words Office 2016
Novice
Using VBA to delete text between two words
 
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
  #2  
Old 01-12-2018, 04:24 AM
macropod's Avatar
macropod macropod is offline Using VBA to delete text between two words Windows 7 64bit Using VBA to delete text between two words Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

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
Using VBA to delete text between two words 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
Using VBA to delete text between two words Remove text between two words VeeCee Word VBA 7 01-05-2014 03:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:04 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft