Answered by:
Microsoft word wildcard question exclude a whole word

Question
-
I have a bunch of lines in a word doc that look like:
Identical Prefix ProjName Group1
Identical Prefix ProjName Group1
Identical Prefix ProjName HappyGroup2
Identical Prefix ProjName Group3
Identical Prefix ProjName Group3
I want to search for the first occurrence of the "next" group, so I want to find the prefix string, plus a different "Group" value, something like "Identical Prefix ProjName [!Group1]"
The problem is that the syntax above looks by letter, not by word. And if I do something like [!G][!r][!o] etc, Word tells me the search is too complicated after seven characters, which is not long enough for my use.
Is there a way to exclude a whole word? [!<Group1>] doesn't work either.
Thanks,
-Mike
Thursday, July 29, 2010 6:23 PM
Answers
-
Use:
Dim rngGroup As Range
Dim rngSearch As Range
Set rngGroup = Selection.Paragraphs(1).Range
Set rngSearch = ActiveDocument.Range
rngSearch.Start = rngGroup.End + 1
rngGroup.End = rngGroup.End - 2
Repeat:
rngSearch.Start = rngSearch.Start + InStr(rngSearch, rngGroup.Text)
If Val(rngSearch.Paragraphs(1).Range.Characters(rngSearch.Paragraphs(1).Range.Characters.Count - 1)) = 1 Then
rngSearch.Start = rngSearch.Paragraphs(1).Range.End
GoTo Repeat
Else
rngSearch.Paragraphs(1).Range.Select
End IfIf you run that code when the first paragraph in the following selected, it will then select the first paragraph that contains "Identical Prefix ProjName Group3"
Identical Prefix ProjName Group1
Identical Prefix ProjName Group1
Identical Prefix ProjName HappyGroup2
Identical Prefix ProjName Group3
Identical Prefix ProjName Group3
-- Hope this helps.Doug Robbins - Word MVP,
dkr[atsymbol]mvps[dot]org
Posted via the Community Bridge"sk00ter21" wrote in message news:86736030-bcf0-46a3-af67-c3a1fea17e4e@communitybridge.codeplex.com...
Thanks, that would be excellent, but the names aren't at all predictable. So I might have "ProjName Audio" and need to get to "ProjName USB" without having to find every Audio line and check its regex.
Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org- Marked as answer by Jennifer Zhan Friday, August 6, 2010 1:43 AM
Tuesday, August 3, 2010 10:49 PM
All replies
-
BumpSaturday, July 31, 2010 3:00 AM
-
How about
"Identical Prefix ProjName Group[!1]"
-- Hope this helps.
Doug Robbins - Word MVP,
dkr[atsymbol]mvps[dot]org
Posted via the Community Bridge"sk00ter21" wrote in message news:8671ab79-e974-4b7b-b401-238f3dce7f0e@communitybridge.codeplex.com...
I have a bunch of lines in a word doc that look like:
Identical Prefix ProjName Group1
Identical Prefix ProjName Group1
Identical Prefix ProjName HappyGroup2
Identical Prefix ProjName Group3
Identical Prefix ProjName Group3
I want to search for the first occurrence of the "next" group, so I want to find the prefix string, plus a different "Group" value, something like "Identical Prefix ProjName [!Group1]"
The problem is that the syntax above looks by letter, not by word. And if I do something like [!G][!r][!o] etc, Word tells me the search is too complicated after seven characters, which is not long enough for my use.
Is there a way to exclude a whole word? [!<Group1>] doesn't work either.
Thanks,
-Mike
Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]orgTuesday, August 3, 2010 5:32 AM -
Thanks, that would be excellent, but the names aren't at all predictable. So I might have "ProjName Audio" and need to get to "ProjName USB" without having to find every Audio line and check its regex.Tuesday, August 3, 2010 2:25 PM
-
You can't really do this without using a 'proper' Regex (with a RexExpobject in VBA). All you can really do in Word is find the next 'IdenticalPrefix ProjName whatever' and check the whatever to see if it what you want.--Enjoy,Tonywww.WordArticles.com"sk00ter21" wrote in message news:8671ab79-e974-4b7b-b401-238f3dce7f0e...>I have a bunch of lines in a word doc that look like:>> Identical Prefix ProjName Group1>> Identical Prefix ProjName Group1>> Identical Prefix ProjName HappyGroup2>> Identical Prefix ProjName Group3>> Identical Prefix ProjName Group3>>>> I want to search for the first occurrence of the "next" group, so I want> to find the prefix string, plus a different "Group" value, something like> "Identical Prefix ProjName [!Group1]">> The problem is that the syntax above looks by letter, not by word. And if> I do something like [!G][!r][!o] etc, Word tells me the search is too> complicated after seven characters, which is not long enough for my use.>> Is there a way to exclude a whole word? [!<Group1>] doesn't work either.>> Thanks,>> -Mike>
Enjoy,
Tony
www.WordArticles.comTuesday, August 3, 2010 5:20 PM -
Use:
Dim rngGroup As Range
Dim rngSearch As Range
Set rngGroup = Selection.Paragraphs(1).Range
Set rngSearch = ActiveDocument.Range
rngSearch.Start = rngGroup.End + 1
rngGroup.End = rngGroup.End - 2
Repeat:
rngSearch.Start = rngSearch.Start + InStr(rngSearch, rngGroup.Text)
If Val(rngSearch.Paragraphs(1).Range.Characters(rngSearch.Paragraphs(1).Range.Characters.Count - 1)) = 1 Then
rngSearch.Start = rngSearch.Paragraphs(1).Range.End
GoTo Repeat
Else
rngSearch.Paragraphs(1).Range.Select
End IfIf you run that code when the first paragraph in the following selected, it will then select the first paragraph that contains "Identical Prefix ProjName Group3"
Identical Prefix ProjName Group1
Identical Prefix ProjName Group1
Identical Prefix ProjName HappyGroup2
Identical Prefix ProjName Group3
Identical Prefix ProjName Group3
-- Hope this helps.Doug Robbins - Word MVP,
dkr[atsymbol]mvps[dot]org
Posted via the Community Bridge"sk00ter21" wrote in message news:86736030-bcf0-46a3-af67-c3a1fea17e4e@communitybridge.codeplex.com...
Thanks, that would be excellent, but the names aren't at all predictable. So I might have "ProjName Audio" and need to get to "ProjName USB" without having to find every Audio line and check its regex.
Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org- Marked as answer by Jennifer Zhan Friday, August 6, 2010 1:43 AM
Tuesday, August 3, 2010 10:49 PM