In the following code why does the line MsgBox aWord.Next return just the
first letter of the next word rather than the complete word? Thanks

Sub Testing()
Dim aWord
For Each aWord In ActiveDocument.Range.Words
MsgBox aWord
MsgBox aWord.Next
Next aWord
End Sub

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

Re: .Next feature by Vince

Vince
Wed Aug 17 20:36:09 CDT 2005

Greg,

I am no expert but I think when you say "aWord.Next" it moves to the next
character by default. This code works:

Dim aWord As Range
For Each aWord In ActiveDocument.Range.Words
MsgBox "BEF: " & aWord & " AFT: " & aWord.Next(unit:=wdWord, Count:=1)
Next aWord

Vince

"Greg Maxey" <gmaxey@mvps.OscarRomeoGolf> wrote in message
news:uhco734oFHA.3960@TK2MSFTNGP12.phx.gbl...
> In the following code why does the line MsgBox aWord.Next return just the
> first letter of the next word rather than the complete word? Thanks
>
> Sub Testing()
> Dim aWord
> For Each aWord In ActiveDocument.Range.Words
> MsgBox aWord
> MsgBox aWord.Next
> Next aWord
> End Sub
>
> --
> Greg Maxey/Word MVP
> See:
> http://gregmaxey.mvps.org/word_tips.htm
> For some helpful tips using Word.
>



Re: .Next feature by Greg

Greg
Wed Aug 17 21:11:56 CDT 2005

Vince,

You come along with a suggestion that works and you are "expert" in my eyes.
Thanks.

Another user and I where discussing using OR in a find text problem. The
discussion turned to a very real human situation where the house is locked
and the car is locked. A known spare house key is in the car and a known
spare car hey is in the house. There are other keys somewhere to be found.
Obviously the problem is resolved and the search can end when either a house
or car key is found.

Cheers

Sub HelmutsDilemma()
Dim aWord As Range
Dim myStr As String
For Each aWord In ActiveDocument.Range.Words
myStr = aWord
If InStrRev(myStr, " ") = Len(myStr) Then
myStr = Left(myStr, (Len(myStr) - 1))
End If
Select Case myStr
Case Is = "car", "house"
If aWord.Next(Unit:=wdWord, Count:=1) = "keys " Or _
aWord.Next(Unit:=wdWord, Count:=1) = "keys" Then
With aWord
.MoveEnd Unit:=wdWord, Count:=1
.Select
End With
Exit Sub
End If
Case Else
'Do Nothing
End Select
Next
End Sub

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

Vince wrote:
> Greg,
>
> I am no expert but I think when you say "aWord.Next" it moves to the
> next character by default. This code works:
>
> Dim aWord As Range
> For Each aWord In ActiveDocument.Range.Words
> MsgBox "BEF: " & aWord & " AFT: " & aWord.Next(unit:=wdWord,
> Count:=1) Next aWord
>
> Vince
>
> "Greg Maxey" <gmaxey@mvps.OscarRomeoGolf> wrote in message
> news:uhco734oFHA.3960@TK2MSFTNGP12.phx.gbl...
>> In the following code why does the line MsgBox aWord.Next return
>> just the first letter of the next word rather than the complete
>> word? Thanks Sub Testing()
>> Dim aWord
>> For Each aWord In ActiveDocument.Range.Words
>> MsgBox aWord
>> MsgBox aWord.Next
>> Next aWord
>> End Sub
>>
>> --
>> Greg Maxey/Word MVP
>> See:
>> http://gregmaxey.mvps.org/word_tips.htm
>> For some helpful tips using Word.



Re: .Next feature by Vince

Vince
Wed Aug 17 21:25:21 CDT 2005

Ah, so it's Helmut Weber's dilemma (he has helped me on many occasions).

Well, I am sure about the human approach to this, which is to break open the
car's window and get the house key. Later, you could get insurance to pay
for the window!

Vince

"Greg Maxey" <gmaxey@mvps.OscarRomeoGolf> wrote in message
news:ueBlxo5oFHA.2580@TK2MSFTNGP09.phx.gbl...
> Vince,
>
> You come along with a suggestion that works and you are "expert" in my
> eyes. Thanks.
>
> Another user and I where discussing using OR in a find text problem. The
> discussion turned to a very real human situation where the house is locked
> and the car is locked. A known spare house key is in the car and a known
> spare car hey is in the house. There are other keys somewhere to be
> found. Obviously the problem is resolved and the search can end when
> either a house or car key is found.
>
> Cheers
>
> Sub HelmutsDilemma()
> Dim aWord As Range
> Dim myStr As String
> For Each aWord In ActiveDocument.Range.Words
> myStr = aWord
> If InStrRev(myStr, " ") = Len(myStr) Then
> myStr = Left(myStr, (Len(myStr) - 1))
> End If
> Select Case myStr
> Case Is = "car", "house"
> If aWord.Next(Unit:=wdWord, Count:=1) = "keys " Or _
> aWord.Next(Unit:=wdWord, Count:=1) = "keys" Then
> With aWord
> .MoveEnd Unit:=wdWord, Count:=1
> .Select
> End With
> Exit Sub
> End If
> Case Else
> 'Do Nothing
> End Select
> Next
> End Sub
>
> --
> Greg Maxey/Word MVP
> See:
> http://gregmaxey.mvps.org/word_tips.htm
> For some helpful tips using Word.
>
> Vince wrote:
>> Greg,
>>
>> I am no expert but I think when you say "aWord.Next" it moves to the
>> next character by default. This code works:
>>
>> Dim aWord As Range
>> For Each aWord In ActiveDocument.Range.Words
>> MsgBox "BEF: " & aWord & " AFT: " & aWord.Next(unit:=wdWord,
>> Count:=1) Next aWord
>>
>> Vince
>>
>> "Greg Maxey" <gmaxey@mvps.OscarRomeoGolf> wrote in message
>> news:uhco734oFHA.3960@TK2MSFTNGP12.phx.gbl...
>>> In the following code why does the line MsgBox aWord.Next return
>>> just the first letter of the next word rather than the complete
>>> word? Thanks Sub Testing()
>>> Dim aWord
>>> For Each aWord In ActiveDocument.Range.Words
>>> MsgBox aWord
>>> MsgBox aWord.Next
>>> Next aWord
>>> End Sub
>>>
>>> --
>>> Greg Maxey/Word MVP
>>> See:
>>> http://gregmaxey.mvps.org/word_tips.htm
>>> For some helpful tips using Word.
>
>



Re: .Next feature by Greg

Greg
Wed Aug 17 21:45:35 CDT 2005

Who said anything about Helmut Weber ;-)


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

Vince wrote:
> Ah, so it's Helmut Weber's dilemma (he has helped me on many
> occasions).
> Well, I am sure about the human approach to this, which is to break
> open the car's window and get the house key. Later, you could get
> insurance to pay for the window!
>
> Vince
>
> "Greg Maxey" <gmaxey@mvps.OscarRomeoGolf> wrote in message
> news:ueBlxo5oFHA.2580@TK2MSFTNGP09.phx.gbl...
>> Vince,
>>
>> You come along with a suggestion that works and you are "expert" in
>> my eyes. Thanks.
>>
>> Another user and I where discussing using OR in a find text problem.
>> The discussion turned to a very real human situation where the house
>> is locked and the car is locked. A known spare house key is in the
>> car and a known spare car hey is in the house. There are other keys
>> somewhere to be found. Obviously the problem is resolved and the
>> search can end when either a house or car key is found.
>>
>> Cheers
>>
>> Sub HelmutsDilemma()
>> Dim aWord As Range
>> Dim myStr As String
>> For Each aWord In ActiveDocument.Range.Words
>> myStr = aWord
>> If InStrRev(myStr, " ") = Len(myStr) Then
>> myStr = Left(myStr, (Len(myStr) - 1))
>> End If
>> Select Case myStr
>> Case Is = "car", "house"
>> If aWord.Next(Unit:=wdWord, Count:=1) = "keys " Or _
>> aWord.Next(Unit:=wdWord, Count:=1) = "keys" Then
>> With aWord
>> .MoveEnd Unit:=wdWord, Count:=1
>> .Select
>> End With
>> Exit Sub
>> End If
>> Case Else
>> 'Do Nothing
>> End Select
>> Next
>> End Sub
>>
>> --
>> Greg Maxey/Word MVP
>> See:
>> http://gregmaxey.mvps.org/word_tips.htm
>> For some helpful tips using Word.
>>
>> Vince wrote:
>>> Greg,
>>>
>>> I am no expert but I think when you say "aWord.Next" it moves to the
>>> next character by default. This code works:
>>>
>>> Dim aWord As Range
>>> For Each aWord In ActiveDocument.Range.Words
>>> MsgBox "BEF: " & aWord & " AFT: " & aWord.Next(unit:=wdWord,
>>> Count:=1) Next aWord
>>>
>>> Vince
>>>
>>> "Greg Maxey" <gmaxey@mvps.OscarRomeoGolf> wrote in message
>>> news:uhco734oFHA.3960@TK2MSFTNGP12.phx.gbl...
>>>> In the following code why does the line MsgBox aWord.Next return
>>>> just the first letter of the next word rather than the complete
>>>> word? Thanks Sub Testing()
>>>> Dim aWord
>>>> For Each aWord In ActiveDocument.Range.Words
>>>> MsgBox aWord
>>>> MsgBox aWord.Next
>>>> Next aWord
>>>> End Sub
>>>>
>>>> --
>>>> Greg Maxey/Word MVP
>>>> See:
>>>> http://gregmaxey.mvps.org/word_tips.htm
>>>> For some helpful tips using Word.



Re: .Next feature by HelmutWeber

HelmutWeber
Thu Aug 18 04:55:28 CDT 2005

Hi everybody,

it seems to me, searching for "this" OR "that"
in a purist sense is impossible. One might model
the human way, as Greg did, or use brute force:

Sub FindFirstOr(strA As String, strB As String)
Dim rDcm As Range
Dim rTmp1 As Range
Dim rTmp2 As Range

Set rDcm = ActiveDocument.Range
' ResetSearch
With rDcm.Find
.Text = strA
If .Execute Then Set rTmp1 = rDcm
End With
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = strB
If .Execute Then Set rTmp2 = rDcm
End With
If rTmp1 Is Nothing And rTmp2 Is Nothing Then
MsgBox "nothing found"
Exit Sub
End If
If rTmp1 Is Nothing Then
rTmp2.Select
Exit Sub
End If
If rTmp2 Is Nothing Then
rTmp1.Select
Exit Sub
End If
If rTmp1.start < rTmp2.start Then
rTmp1.Select
Else
rTmp2.Select
End If
' ResetSearch
End Sub
' -------
Sub test000()
Call FindFirstOr("Housekey", "Carkey")
End Sub

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000