With docObj.Sections(1).Headers(wdHeaderFooterPrimary).Range Set wordObj = CreateObject("Word.Application") Set docObj = (path) Set header = docObj.Sections(1).Headers(wdHeaderFooterPrimary)
I modified your code to look like more the initial: Fields.Add Range:=.Characters(6), Type:=wdFieldEmpty, Text:="PAGE", PreserveFormatting:=False Fields.Add Range:=.Characters(8), Type:=wdFieldEmpty, Text:="NUMPAGES", PreserveFormatting:=False Fields.Add Range:=.Characters(11), Type:=wdFieldEmpty, Text:="DATE", PreserveFormatting:=False Set header = docObj.Sections(1).Headers(wdHeaderFooterPrimary) Set wordObj = CreateObject("Word.Application") If you're wedded to defining a header object, though, you could use: The code I posted is more efficient than either of your approaches. Range:=(11), Type:=wdFieldEmpty, Text:="DATE", PreserveFormatting:=False If you're going to take that approach, you'd need to use: Range:=.Characters(11), Type:=wdFieldEmpty, Text:="DATE", PreserveFormatting:=False Code like ' InsertAfter wdFieldNumPages' would insert as text only the numeric constant that wdFieldNumPages represents - in this case, 26.Īs for your follow-up, presumably your code is failing at: No, your code wasn't actually adding any fields. Characters(11)" field where I was using "Fields.Add header.Range" and probably I was adding a new whole range from the beggining, right? Press the “Tab” key twice or more as needed to reposition the cursor where you want page numbers displayed.Actually, I was stuck to the ".Fields.Add Range:=.Click on “Edit Header,” then type your header into the text field.
Click on the “Insert” tab at the top of your document, then click on “Header”.Type up your document before adding a running head. Make all necessary formatting changes in the Modify Style dialog box.Select the menu arrow to the right of the heading you want to customize.Select the Styles dialog box launcher to open the Styles pane.Select the Home tab in the ribbon (see figure 1). How can I change heading levels in Microsoft Word? Type within the separate headers on each page to create your different headers. Click on the “Switch Between Header and Footer” icon to go to either the header or footer in the document. How do you make a different header in word?Ĭlick on the “View” option and then click on the “Header and Footer” option again to bring up the “Formatting” menu for headers and footers. How do I add sub headings in Word? How do you insert a heading in Microsoft Word?Īdding a Header Open Microsoft Word. Then right click on the desired Heading style you wish that text to resemble and select “Update Heading to Match Selection.” This will modify all the headings for this document. The headings should be nested in a logical manner. Click Headings to display the headings hierarchically. How do I get headings to show in navigation pane?Ĭheck the Navigation Pane option in the Show group (OR press Ctrl+F). If you’ve applied heading styles to the headings in the body of your document, those headings appear in the Navigation pane. To open the Navigation pane, press Ctrl+F, or click View > Navigation Pane. To go to a page or a heading in a Word document without scrolling, use the Navigation pane. How do I show headings in Word navigation? Under List Library, choose the numbering style you would like to use in your document.On the Home tab, in the Paragraph group, choose Multilevel List.Open your document that uses built-in heading styles, and select the first Heading 1.Click References > Table of Contents and then choose an Automatic Table of Contents style from the list. How do I create a heading and table of contents in Word?Ĭlick where you want to insert the table of contents – usually near the beginning of a document. Go to Home > Styles, and then choose Heading 1. How do you add a heading to a table of contents in Word?įor each heading that you want in the table of contents, select the heading text. Save your file to save your new heading.Press Enter on your keyboard to move your cursor to the next line.Select the appropriate heading level in the Styles group.So far I managed to do the following with the header but not the core of what I wanted to: Set wordObj CreateObject('Word. Select the text you want to turn into a heading. I did a very expensive research in this forum and online but I cannot find a way to insert page X of Y in the header of a document inbetween text.
How to Create Headings Using Word’s Built-In Heading Styles