
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