Click here to Skip to main content
15,909,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in my word Document(*.doc) I Want highlight the text "I have".if i loop through the words i am gettiing only the "I" as one word and "have" is another word. i want to Highlight the entire string at the same time.How can i do? thank you!
Posted

You need to create Range that contains all characters you wish to highlight.

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.range(v=Office.11).aspx[^]
 
Share this answer
 
I do not quit understand what you are meaning,Can you give me the code?thank you!
 
Share this answer
 
You can use this code:
private void FindLoop()
{
    int intFound = 0;
    Word.Document document = this.Application.ActiveDocument;
    Word.Range rng = document.Content;
    rng.Find.ClearFormatting();
    rng.Find.Forward = true;
    rng.Find.Text = "I have";
    rng.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 (rng.Find.Found)
    {
        intFound++;
        rng.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);
    }
    MessageBox.Show("Strings found: " + intFound.ToString());
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900