Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 14th, 2012, 03:14 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Sep 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Deleting variable ranges based on keyword

So basically what I'm looking to do is sort a long document of text entries in the following format:


each separated by one or more spaces.

What I want to do is delete between "Name" and "Location: " if the keyword is found in the body of text. There may be zero, one or many instances of the keyword throughout the document.

What I have so far is listed below. It works, but only if the keyword is within the very first body of text and it will keep deleting any contiguous keyword containing paragraphs after that. But, it does nothing if the keyword is not in the first body of text.
Set range1 = ActiveDocument.Content
Set range2 = ActiveDocument.Content
Set range3 = ActiveDocument.Content
range1.Find.Execute FindText:="Name", _
range2.Find.Execute FindText:="Location: ", _
If range1.Find.Found = True And range2.Find.Found = True Then
range3.SetRange (range1.End - 4), (range2.End + 1)
End If

range3.Find.Execute FindText:="Orthopaedic", _

If range3.Find.Found = True Then
range3.SetRange (range1.End - 4), (range2.End + 1)
End If

I would greatly appreciate any help y'all would see fit to offer.


Reply With Quote
  #2 (permalink)  
Old March 18th, 2013, 12:56 PM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts


One simple option is to use Regular Expressions (Regex) and find the pattern and then delete it

Else you can place Bookmarks for both words and delete the Range that is between those bookmarks

C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
variable space deleting between the tags rajashekhara XSLT 2 December 18th, 2008 12:45 AM
variable space deleting between the tags rajashekhara XSLT 5 December 17th, 2008 07:17 AM
deleting records based on selected checkbox lakshmi_annayappa Javascript 3 September 6th, 2007 02:22 AM
Variable data Ranges dgarcia1128 Excel VBA 3 June 20th, 2003 02:11 PM
Variable data ranges for charts Cclhodges Excel VBA 1 June 12th, 2003 02:18 AM

All times are GMT -4. The time now is 06:37 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.