0

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;
        }
1
Contributor
1
Reply
11
Views
5 Months
Discussion Span
Last Post by PerplexedB
0

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();          
        }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.