.Net, Word and formatting


i need code to programmatically change the format type to be header 1 or header 2.
Can anyone help? I am using Word 2003
Who is Participating?
Daniel ReynoldsConnect With a Mentor Software Applications Developer / IntegratorCommented:
Once you have your selection, the following code will change the format of the selection to header type x

    Selection.Style = ActiveDocument.Styles("Heading 1")

    Selection.Style = ActiveDocument.Styles("Heading 2")
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
(sheepishly) I'll take the points ;-)
cossy74Author Commented:
xDJR1875: pretty close. The actual code is

                Word.Style GetStyle(string stylename)
                  foreach(Word.Style style in oDoc.Styles)
                        if (style.NameLocal == stylename)
                              return style;
                  return GetStyle("Normal");
            public void SetStyle(string stylename)
                  object newstyle = GetStyle(stylename);
                  oWordApplic.Selection.set_Style(ref newstyle);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.