Man, concentrating on this is tough while Buffy is on TV (actually BuffyBot in this arc)
Thank you for the evaluation. I incorporated almost all your changes. Dohhhh - of course, you can't exit while but you can exit Do - thanks.
Selection.Start = iInitSelStart + 1
is a strange animal, having to do with how .Find.Execute operates. I would appreciate help testing this on other word versions.
Make your document consist entirely of simply the 4 bytes aeae and put the cursor at start of the doc and run CompoundFind as is, answering a,e to the prompt. It finds everything, one by one. But use Selection.Start=iInitSelStart (no +1 ), and it only finds the letter e. Quite bizarre.
If the +1 is instead removed from the line near the end of the while loop, then the last find occurrence fails. Brutal.
AAR as I'm resigned to its necessity (and I've hoisted it for the next update).
Not for war, but I added a thread "CompoundFind style" to explain "formatting differences."
Second version. I'm still open to enhancements/cleanups before KBing it.
'This is a nonwrapping FORWARD search for "OR" arguments, comma-separated.
'It changes current selection when the search succeeds; otherwise
'selection only affects the scope of CompoundFind (not CompoundFindNext)
'Notice that it uses the static variable sResp$, defined atop this module
'Dim sResp$
'Usage examples:
'Type(without the quotes)"a,e,i,o,u" in InputBox & it goes to next vowel
'Type(without the quotes) "Bill,Billy,William" in InputBox & watch it work!
Sub CompoundFind() 'you're nuts not to keyboard accel. these two...
CompoundFindCommonCode (True)
End Sub
Sub CompoundFindNext()
CompoundFindCommonCode (False)
End Sub
Sub CompoundFindCommonCode(bPrompt As Boolean)
Dim iInitSelStart&,iInitSelEnd&,iCommaPos&,iSavPos&,iTrialPos&,iNewPos&,iNewPosLen&
Dim sStr$, bFound As Boolean
'There's an underscore _ at end of next line in case you can't see it
If bPrompt Then sResp=InputBox$("Type multiple ' Or ' Find items,comma separated " _
& vbCr & "( Use \, for actual comma) ", "MultiFind", sResp)
If sResp = "" Then Exit Sub
iInitSelStart = Selection.Start: iInitSelEnd = Selection.End 'for ensuing Finds
Selection.Start = iInitSelStart + 1 'looks queer, but required in W97
iNewPos = iInitSelStart 'our target - where we will go when done
iNewPosLen = iInitSelEnd - iInitSelStart + 1
iCommaPos = 1: iSavPos = 1: bFound = False
While iCommaPos > 0 'always do at least one Find
iCommaPos=InStr(iSavPos,sResp,",") 'this or next Instr'll decide the Wending
If iSavPos <= Len(sResp) Then sStr = Mid$(sResp, iSavPos) 'provisional
If iCommaPos>0 Then 'to restate sStr(if iCommaPos reveals DELIMITING comma)
If iCommaPos <> 1 Then
Do
If Not Mid$(sResp, iCommaPos - 1, 1) = "\" Then Exit Do
sResp = Left$(sResp, iCommaPos - 2) + Mid$(sResp, iCommaPos)
sStr = Mid$(sResp, iSavPos) 'again provisionally in case no commas
iCommaPos = InStr(iCommaPos, sResp, ",") 'not (iCommaPos+1,
If iCommaPos = 0 Then Exit Do
Loop
End If
If iCommaPos > 0 Then sStr = Mid$(sResp, iSavPos, iCommaPos - iSavPos)
iSavPos = iCommaPos + 1
End If
If sStr <> "" Then
With Selection.Find
.Forward = True: .Wrap = wdFindStop: .Execute FindText:=sStr
End With
End If
If Selection.Find.Found Then
bFound = True: iTrialPos = Selection.Start
If iNewPos = iInitSelStart Then 'trial's our very first hit - save it
iNewPos = iTrialPos: iNewPosLen = Len(sStr)
Else 'else iNewPos DID have prior value; update if sooner in file
If iTrialPos<iNewPos Then iNewPos=iTrialPos: iNewPosLen=Len(sStr)
End If
End If
Selection.Start = iInitSelStart + 1: Selection.End = iInitSelEnd
Wend
If bFound Then Selection.Start=iNewPos: Selection.End=iNewPos+iNewPosLen _
Else MsgBox "Solly, no, Cholly"
End Sub
Forgive the indenting. I don't have control over the tag (do I?!). It looks fantastic on MY PC