Solved

.Net, Word  and formatting

Posted on 2007-03-19
4
246 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

21 Experts available now in Live!

Get 1:1 Help Now