I am trying to insert a paragraph with a heading and some text into a word document.
Everything works fine except when I apply the heading style it changes the style of the following text, or, when I change the paragraph body back to "Normal" it changes the heading back to plain text. I cannot get word to recognize them as separate paragraphs, obviously I am doing something very wrong but I just cannot see what. Actual code is attached:-
Word.Paragraph p2 = wD.Paragraphs.Add(R.End);
Word.Range r2 = p2.Range;
r2.InsertAfter("If any updates were made then link to the follow on program "
+ curTarget.followOn + ".\n");
string style = "Normal";
object objStyle = style;
r2.set_Style(ref objStyle);
r2.InsertParagraphAfter();
Word.Paragraph p3 = wD.Paragraphs.Add(r2);
Word.Range r3 = p3.Range;
r3.Text = "Call follow on process.\n";
style = "Heading 4";
objStyle = style;
r3.set_Style(ref objStyle);
r2.InsertParagraphAfter();
Apologies for the messy code but its been re(de)-factored about twenty times.
set_Style
syntax. Could that be part of the confusion? – Paul Bellora