tags:

views:

61

answers:

2

Hi there,

I can find Text in word via:

Word.Range range = wordApp.ActiveDocument.Content;
Word.Find find = range.Find;
find.Text = "xxx";
find.ClearFormatting();
find.Execute(ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing);

This tells me if the text ist found. But I need the range of the found text-piece. I really don't know how to get it. Would be nice if you could help me out.

Greets

Simon

A: 

The range object should be changed by executing find on it.

So, likely you'd use range.Start and range.End to get the character positions. Reference

mootinator
+1  A: 

Have you tried this:

 range.Find.Execute(
      ref missing, ref missing, ref missing, ref missing, ref missing, 
      ref missing, ref missing, ref missing, ref missing, ref missing,
      ref missing, ref missing, ref missing, ref missing, ref missing);


 while (range.Find.Found) 
{ 
   //Get selected index.
   // Do as you please with range...
   //Positions:  range.Start... range.End
   //search again
   range.Find.Execute(
      ref missing, ref missing, ref missing, ref missing, ref missing, 
      ref missing, ref missing, ref missing, ref missing, ref missing,
      ref missing, ref missing, ref missing, ref missing, ref missing);
} 
Nix
Hey this seems to work. Don't know how I tried before, but thanks at all.
simon