Click here to Skip to main content
13,087,941 members (62,227 online)
Rate this:
Please Sign up or sign in to vote.
See more:
foreach (Microsoft.Office.Interop.Word.Range rng in doc.StoryRanges)
    bool hasFound = false;
    rng.Find.Text = findWhat;
    rng.Find.Replacement.Text = replaceText;
    rng.Find.Forward = true;
    rng.Find.MatchCase = false;
    rng.Find.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindStop;
    rng.Find.Format = true;
    hasFound = rng.Find.Execute(Replace:  

When i execute function,it changes formatting of text,original text is underlined but it makes it plain. Any ideas? Thanks

My state is different; Original String -> ^tcookie, i want to make first letter after Tabs upper so i replace ^tc -> ^tC
When i do it, final text becomes ^tCookie. How can i fix it?
Posted 5-Oct-11 10:49am
Updated 5-Oct-11 11:42am
Edward Nutting 5-Oct-11 16:56pm
Try removing the rng.Find.Replacement.ClearFormatting() - it seems like a pretty obvious line of code that may be causing your problem though I'm not familiar with these methods it seems likely. (p.s. Edit was : Sorted formatting.)
emrea 5-Oct-11 17:13pm
I tried it but still same.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

As far as I understand the Find Interface[^] and Replacement Interface[^] you need to replace
rng.Find.Format = true;
rng.Find.Format = false;
and it should work.
emrea 5-Oct-11 17:28pm
Still same,it changes underlined text to non-underlined.When i do it in Word find&replace,it doesn't do same thing.
André Kraak 5-Oct-11 17:39pm
Try leaving out the line rng.Find.Format entirely.
André Kraak 5-Oct-11 17:42pm
You could also try adding the line rng.Find.ClearFormatting();

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 5 Oct 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100