View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Sarvesh Sarvesh is offline
external usenet poster
 
Posts: 2
Default Word Search from Excel results in Duplicates

Hi Jane:

Thanks for pointing me in the right direction. I resolved my problem
by adding the following code prior to initiating the second search

wrdApp.Selection.HomeKey Unit:=wdStory

This sets the cursor back to the start of the document and avoids the
duplicate selection when the search wraps around. Since I am doing
multiple searches, this significantly optimizes my performance (as
opposed to closing and re-opening the document each time)

regards
-Sarvesh

("Jane Pratt [MSFT]") wrote in message ...
Hi

I think the problem is probably that the second search only searches the
end of the document (from the last match to the first search). You have
included the following line of code:
.Wrap = wdFindContinue

but if you do not have a reference to Word, the constant value for
wdFindContinue (1) will not have been set. There are a couple of possible
solutions for this:
- Change the code to use the value rather than the constant:
.Wrap = 1
- Set the value of wdFindContinue in your code:
wdFindContinue=1

The same problem could occur with the first search if the cursor is not at
the start of the document when the search occurs.

I hope that this helps!

Regards
Jane Pratt
Developer Tools Support
Microsoft UK

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.