VBA to select all text bewteen 2 different search strings and delete 
Author Message
 VBA to select all text bewteen 2 different search strings and delete

Folks I need some help,
   I'm trying to write word 2000 macro which will find and
delete all text between two different search variables.  
The documents I'm working with may have different numbers
of lines etc, but I want to delete all text between two
different Find commands and then continue to iterate until
the finds are false.
  Any help would be most greatly appreciated.
  Thanks,
   Pitt


Sun, 04 Apr 2004 10:34:23 GMT  
 VBA to select all text bewteen 2 different search strings and delete
Pitt,

Unless I'm misunderstanding the task, you should be able to do this
with a simple wildcard search.  In code this could look like:

Dim var1 As String, var2 As String
var1 = InputBox("Enter search string #1")
var2 = InputBox("Enter search string #2")
If var1 = "" Or var2 = "" Then MsgBox "Tsk... quitter!": Exit Sub
With Selection.Find
   .Text = "(" & var1 & ")*(" & var2 & ")"
   .Replacement.Text = "\1\2"
   .Wrap = wdFindContinue
   .Forward = True
   .Format = False
   .MatchCase = False
   .MatchWildcards = True
   .Execute Replace:=wdReplaceAll
End With


-- See the MVP FAQ at http://www.mvps.org/word --------------------
----------- "Life is nothing if you're not obsessed." --John Waters
-------------------------------------------------------------------
Please reply only to the newsgroup.

Quote:

> Folks I need some help,
>    I'm trying to write word 2000 macro which will find and
> delete all text between two different search variables.
> The documents I'm working with may have different numbers
> of lines etc, but I want to delete all text between two
> different Find commands and then continue to iterate until
> the finds are false.
>   Any help would be most greatly appreciated.
>   Thanks,
>    Pitt



Sun, 04 Apr 2004 12:01:40 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. excel vba - help finding designated text within string and deleting selected range's row

2. select text between two different strings

3. CODE: Select text string in cell and delete?

4. How can I use VBA to search all modules for a text string

5. Search for a text string in text file

6. CODE: How to Select Entire String (Sentence) and Delete

7. Selecting Text from one file and copying to a different file

8. Searching and Deleting from text files

9. Euivelant string searches in VBA

10. Search and select text in email item, convert to hyperlink

11. Search-and-replace only in selected text

12. How to select text with search

 

 
Powered by phpBB® Forum Software