Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2007

Tip: Looking for answers? Try searching our database.

Word's "Find" not working as expected

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Omatase - 01 Oct 2007 17:29 GMT
I have a string of text found twice in the same word document. Even
though I indicate a starting point that is before the first instance
of this string and I mark Forward = true the first instance it finds
is the instance at the end of the document. Is there some trick I can
apply to cause it consistently to find the first instance?

Here is my code (aDoc is a Document):

object missingValue = System.Reflection.Missing.Value;

object start = 0;
object end = aDoc.Content.End;

searchResultRange = aDoc.Range(ref start, ref end);
searchResultRange.Find.ClearFormatting();
searchResultRange.Find.Forward = true;
searchResultRange.Find.Text = "zip";
searchResultRange.Find.Wrap = WdFindWrap.wdFindStop;

searchResultRange.Find.Execute(ref missingValue, ref missingValue,
   ref missingValue, ref missingValue, ref missingValue,
   ref missingValue, ref missingValue, ref missingValue,
   ref missingValue, ref missingValue, ref missingValue,
   ref missingValue, ref missingValue, ref missingValue,
   ref missingValue);

I am using Word XP
Shauna Kelly - 02 Oct 2007 12:06 GMT
Hi Omatose

My first check would be to ensure that there are no settings in the .Find
object carried over from former use in the UI or code. For example, if you'd
previously used .MatchCase and one of the "zip" texts was actually "Zip",
the .Find would fail.

For more info and sample code, see the ClearFindAndReplaceParameters routine
at
http://www.word.mvps.org/FAQs/MacrosVBA/FlushFR.htm

For what it's worth, I run code like that before any .Find operation.

Hope this helps.

Shauna Kelly.  Microsoft MVP.
http://www.shaunakelly.com/word

>I have a string of text found twice in the same word document. Even
> though I indicate a starting point that is before the first instance
[quoted text clipped - 23 lines]
>
> I am using Word XP
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.