In the Styles Toolbox, click the style you want to apply. Click the style that appears in the Style Area left of the subheading. ''' Dim objWord As Word. How do I link headings and subheadings in Word Type in the text for the subheading. '' requires adding Microsoft Word XX.Y Object Library" reference to your project
#How to apply heading styles in word code#
You may also want to use With - End With syntax to clean up your code and make it more readable, robust and faster Option Explicit Set Selection object of the wanted document any window Set objSelection = Įxplicitly reference Word application active document: objSelection.Style = ("Heading 2") ObjSelection.TypeText Text:=myRange(i, k) ObjSelection.Style = ActiveDocument.Styles("Normal") ObjSelection.TypeText Text:=myRange(1, k) ObjSelection.Style = ActiveDocument.Styles("Heading 4") ObjSelection.TypeText Text:=myRange(i, 2) ObjSelection.Style = ActiveDocument.Styles("Heading 3") While you can create your own styles and use those as headings, or adjust the formatting of headings look on the fly, you can also change the default styles if you want. The styles define the font family, size, color, and more. ObjSelection.TypeText Text:=myRange(i, 1) Word provides built-in styles for several different levels of headings and subheadsHeading 1, Heading 2, and so on. ObjSelection.Style = ActiveDocument.Styles("Heading 2") Set objWord = CreateObject("Word.Application") Here is the code: 'Create the word document I would like to create some of the text in different styles, but keep getting Run time error 430 (Class does not support Automation or does not support expected interface) Here is the code i have in Excel to control a word document, and publish it with some data.