user734178
user734178

Reputation: 43

How to use Heading Style while automating word in C#?

My program is copying string from other file and it should convert as heading while pasting in word. (MS 2007). I tried recording macro:

Selection.PasteAndFormat (wdPasteDefault)
Selection.Style = ActiveDocument.Styles("Heading 2").

But how to do it in C#?

Upvotes: 0

Views: 2483

Answers (1)

user734178
user734178

Reputation: 43

Ok this is what I did:

object headingType = Word.WdBuiltinStyle.wdStyleHeading2;
wordApp.ActiveWindow.Selection.Range.PasteAndFormat(WdRecoveryType.wdPasteDefault);
wordApp.ActiveWindow.Selection.Range.set_Style(ref headingType);

Upvotes: 1

Related Questions