Solved

.Net, Word  and formatting

Posted on 2007-03-19
4
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

752 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