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