Thread: [Solved] Range.Collapse?
View Single Post
 
Old 01-16-2013, 12:12 PM
fumei fumei is offline Windows 7 64bit Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

Oooops, sorry. That is what I get having multiple forums open at the same time. I was responding to something else. My bad.

However, to answer the question, the Collapse itself does not really do anything...welll not technically true. It DOES collapse the range, but that itself has no real effect. Or rather, there is an effect but it makes no difference.

During a Find operation, the actual range object is changed to each Found. This is happening. It then moves on to the next Found.

You use a Collapse instruction when you CHANGE something in the Found. Say you find "cat", and you change the "c" to an "h". Because there is a change (and it more noticeable in a format rather than textual change), the Find operation starts up again at the START of the last Found (i.e "hat"). In this case, the Find will ignore "hat" (because the Find text is "cat"). It moves on searching for the next "cat".

But suppose you had a Bold operation to the found - that is "cat" remains "cat", but bolded. In that case, when the change to the range is done, Find starts up again at the START of the last Found - i.e the SAME "cat" found. In which case the code keeps on finding the same instance of "cat".

Thus the need for a Collapse. The "cat" is found, the bold is applied, the range is collapsed to the END of the found range, and starts again...thus going on to the NEXT "cat".

You use a Collapse when there is a change to the found range.
Reply With Quote