0

I have two consecutive paragraphs, the second has some text formatted italics. I add the text of the second paragraph to the first by setting the range of the first paragraph then using this code:

Paragraph nextPar = firstPar.Next();
Range nextRange = nextPar.Range;
firstRng.InsertAfter(nextRange.Text.ToString());

This works well but it removes the italic from the text of the second paragraph. I want a way to keep formatting.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Lucky Luke2
  • 2,056
  • 5
  • 25
  • 32

1 Answers1

0

Italics (or bold or any other style) is applied to the whole range. With InsertAfter, you are just putting more text in the same range and thus implicitly accepting the given format. You have to rely on two different ranges to allow italics/non italics.

Just keep adding paragraphs and account for as many different ranges as different styles you want. Here you have examples showing how to include different styles (ranges) in the same line.

Community
  • 1
  • 1
varocarbas
  • 12,354
  • 4
  • 26
  • 37
  • Thanks for help and reply. But it is the Italics from the second parapgraph that i want to keep. The text that i add to the firstRng. Maybe i misunderstand you. Also, the whole range is not italics so making it italic is not i what i need, thanks. – Lucky Luke2 Jul 04 '13 at 08:02
  • No, I was the one misunderstanding your question. In this case, you cannot rely on the same range. When you do InsertAfter you are just extending the first range and this range can have italics or not, but not both. Sorry about the misunderstanding (answering too quickly have this kind of things ;)), you can read my new answer. – varocarbas Jul 04 '13 at 08:04
  • I have updated my resply again with a link giving some alternatives to include different styles in the same line. – varocarbas Jul 04 '13 at 08:28