Hi i want to select some text throughout a document to be deleted. The
test will look like this......

'Christmas : 2 x 5" Fruit & Cone Candle Rings Product: Christmas 2 x
5" Fruit & Cone Candle Rings Custom Label: 213878'

I want to select the word 'Product' and everything up to (but NOT
including) the word Label and then delete that selection.

I want this to loop through the document until there are no more
Products to be found

Any help is appreciated

Re: Selecting text between 2 found words in Word by Greg

Greg
Thu Nov 30 08:17:32 CST 2006

Richy,

You don't need a macro for this. You could do it directly from the
find and replace dialog:
Sub Scratchmacro2()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Content
With oRng.Find
.Text = "Product*Label"
.MatchWildcards = True
.Replacement.Text = "Label"
.Execute Replace:=wdReplaceAll
End With
End Sub

Richy wrote:
> Hi i want to select some text throughout a document to be deleted. The
> test will look like this......
>
> 'Christmas : 2 x 5" Fruit & Cone Candle Rings Product: Christmas 2 x
> 5" Fruit & Cone Candle Rings Custom Label: 213878'
>
> I want to select the word 'Product' and everything up to (but NOT
> including) the word Label and then delete that selection.
>
> I want this to loop through the document until there are no more
> Products to be found
>
> Any help is appreciated


Re: Selecting text between 2 found words in Word by John

John
Thu Nov 30 09:34:56 CST 2006

Greg Maxey wrote:
> Richy,
>
> You don't need a macro for this. You could do it directly from the
> find and replace dialog:
> Sub Scratchmacro2()
> Dim oRng As Word.Range
> Set oRng = ActiveDocument.Content
> With oRng.Find
> .Text = "Product*Label"
> .MatchWildcards = True
> .Replacement.Text = "Label"
> .Execute Replace:=wdReplaceAll
> End With
> End Sub
>
> Richy wrote:
>> Hi i want to select some text throughout a document to be deleted. The
>> test will look like this......
>>
>> 'Christmas : 2 x 5" Fruit & Cone Candle Rings Product: Christmas 2 x
>> 5" Fruit & Cone Candle Rings Custom Label: 213878'
>>
>> I want to select the word 'Product' and everything up to (but NOT
>> including) the word Label and then delete that selection.
>>
>> I want this to loop through the document until there are no more
>> Products to be found
>>
>> Any help is appreciated
>
Greg,

Your answer makes me realize once again how little I know about the
Search&Replace function. The sites I know about this are neither
exhaustive nor user friendly (meaning clear to understand for a
beginner). Hence my first question, can you suggest a fairly
comprehensive yet clear site ?

Second, to elaborate on the above macro, what if the user wanted a macro
prompting him for the first and then the last words, as here, "Product"
and "label" and then 2hich would display the number of replacement?

Regards

--
John Doue

Re: Selecting text between 2 found words in Word by Graham

Graham
Thu Nov 30 09:52:32 CST 2006

You should find http://www.gmayor.com/replace_using_wildcards.htm both
exhaustive and user friendly. If not let me know why, via the feedback link
on my web site.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

John Doue wrote:
> Greg Maxey wrote:
>> Richy,
>>
>> You don't need a macro for this. You could do it directly from the
>> find and replace dialog:
>> Sub Scratchmacro2()
>> Dim oRng As Word.Range
>> Set oRng = ActiveDocument.Content
>> With oRng.Find
>> .Text = "Product*Label"
>> .MatchWildcards = True
>> .Replacement.Text = "Label"
>> .Execute Replace:=wdReplaceAll
>> End With
>> End Sub
>>
>> Richy wrote:
>>> Hi i want to select some text throughout a document to be deleted. The
>>> test will look like this......
>>>
>>> 'Christmas : 2 x 5" Fruit & Cone Candle Rings Product: Christmas 2
>>> x 5" Fruit & Cone Candle Rings Custom Label: 213878'
>>>
>>> I want to select the word 'Product' and everything up to (but NOT
>>> including) the word Label and then delete that selection.
>>>
>>> I want this to loop through the document until there are no more
>>> Products to be found
>>>
>>> Any help is appreciated
>>
> Greg,
>
> Your answer makes me realize once again how little I know about the
> Search&Replace function. The sites I know about this are neither
> exhaustive nor user friendly (meaning clear to understand for a
> beginner). Hence my first question, can you suggest a fairly
> comprehensive yet clear site ?
>
> Second, to elaborate on the above macro, what if the user wanted a
> macro prompting him for the first and then the last words, as here,
> "Product" and "label" and then 2hich would display the number of
> replacement?
> Regards



Re: Selecting text between 2 found words in Word by John

John
Thu Nov 30 12:07:19 CST 2006

Graham Mayor wrote:
> You should find http://www.gmayor.com/replace_using_wildcards.htm both
> exhaustive and user friendly. If not let me know why, via the feedback link
> on my web site.
>
Thanks a million, I did not know it. I will definitely learn a lot from it.

Best regards
--
John Doue

Re: Selecting text between 2 found words in Word by Greg

Greg
Thu Nov 30 17:40:57 CST 2006

John,

Again you don't need a macro to do this either. After reviewing Graham's
article I think you will see why. Here is the code that would do that for
you:

Sub Scratchmacro()
Dim oRng As Word.Range
Dim sFind1 As String
Dim sFind2 As String
Dim Count As Long
Set oRng = ActiveDocument.Content
sFind1 = InputBox("Type leading word to find.", "Leading Word")
sFind2 = InputBox("Type trailing word to find.", "Trailing Word")
With oRng.Find
.Text = sFind1 & "*" & sFind2
.MatchWildcards = True
While .Execute
oRng = sFind2
oRng.Collapse wdCollapseEnd
Count = Count + 1
Wend
End With
MsgBox Count
End Sub

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


John Doue wrote:
> Greg Maxey wrote:
>> Richy,
>>
>> You don't need a macro for this. You could do it directly from the
>> find and replace dialog:
>> Sub Scratchmacro2()
>> Dim oRng As Word.Range
>> Set oRng = ActiveDocument.Content
>> With oRng.Find
>> .Text = "Product*Label"
>> .MatchWildcards = True
>> .Replacement.Text = "Label"
>> .Execute Replace:=wdReplaceAll
>> End With
>> End Sub
>>
>> Richy wrote:
>>> Hi i want to select some text throughout a document to be deleted. The
>>> test will look like this......
>>>
>>> 'Christmas : 2 x 5" Fruit & Cone Candle Rings Product: Christmas 2
>>> x 5" Fruit & Cone Candle Rings Custom Label: 213878'
>>>
>>> I want to select the word 'Product' and everything up to (but NOT
>>> including) the word Label and then delete that selection.
>>>
>>> I want this to loop through the document until there are no more
>>> Products to be found
>>>
>>> Any help is appreciated
>>
> Greg,
>
> Your answer makes me realize once again how little I know about the
> Search&Replace function. The sites I know about this are neither
> exhaustive nor user friendly (meaning clear to understand for a
> beginner). Hence my first question, can you suggest a fairly
> comprehensive yet clear site ?
>
> Second, to elaborate on the above macro, what if the user wanted a
> macro prompting him for the first and then the last words, as here,
> "Product" and "label" and then 2hich would display the number of
> replacement?
> Regards



Re: Selecting text between 2 found words in Word by John

John
Fri Dec 01 03:02:37 CST 2006

Greg Maxey wrote:
> John,
>
> Again you don't need a macro to do this either. After reviewing Graham's
> article I think you will see why. Here is the code that would do that for
> you:
>
> Sub Scratchmacro()
> Dim oRng As Word.Range
> Dim sFind1 As String
> Dim sFind2 As String
> Dim Count As Long
> Set oRng = ActiveDocument.Content
> sFind1 = InputBox("Type leading word to find.", "Leading Word")
> sFind2 = InputBox("Type trailing word to find.", "Trailing Word")
> With oRng.Find
> .Text = sFind1 & "*" & sFind2
> .MatchWildcards = True
> While .Execute
> oRng = sFind2
> oRng.Collapse wdCollapseEnd
> Count = Count + 1
> Wend
> End With
> MsgBox Count
> End Sub
>
Thanks Greg!

--
John Doue