Solved

.Net, Word  and formatting

Posted on 2007-03-19
4
257 Views
Last Modified: 2010-04-14
Hi,

i need code to programmatically change the format type to be header 1 or header 2.
Can anyone help? I am using Word 2003
0
Comment
Question by:cossy74
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
xDJR1875 earned 500 total points
ID: 18748342
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")

or
    Selection.Style = ActiveDocument.Styles("Heading 2")
0
 
LVL 17

Expert Comment

by:xDJR1875
ID: 18886735
(sheepishly) I'll take the points ;-)
0
 

Author Comment

by:cossy74
ID: 18894349
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);
            }
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now