Solved

.Net, Word  and formatting

Posted on 2007-03-19
4
264 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:
Daniel Reynolds 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:Daniel Reynolds
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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 …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

816 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

11 Experts available now in Live!

Get 1:1 Help Now