Hi have this code that runs well for me. It's part of my WordWrapper where Sel is defined as the Selection object.
I tried to save Sel.Font to a var f variable, and reset Sel.Font = fbefore exit, but that does not work. "Value out of range".

        /// <summary>
        /// Write String Bold/Underline/Size 14.
        /// </summary>
        /// <param name="s"></param>
        public void Header(string s)
        {
            var b = Sel.Font.Bold;
            var u = Sel.Font.Underline;
            var size = Sel.Font.Size;
            Sel.Font.Bold = (int) Word.WdConstants.wdToggle;
            Sel.Font.Underline = Word.WdUnderline.wdUnderlineSingle;
            Sel.Font.Size = 14;
            Sel.TypeText(s);
            Sel.Font.Bold = b;
            Sel.Font.Underline = u;
            Sel.Font.Size = size;
        }

This looks slightly better and uses built in styles.

       public void Header(string s)
        {
            Sel.TypeText(s);
            var p = Sel.Paragraphs.Last;
            p.set_Style(Word.WdBuiltinStyle.wdStyleHeading1);
            Sel.TypeParagraph();          
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.