O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13. The Section and HeaderFooter Objects

In this chapter:

  • Adding a New Section

  • The PageSetup Object

  • Properties of the Section Object

  • The HeaderFooter Object

The Section object represents a section in a document, range, or selection. Section objects are stored in the Sections collection. Each of the Document, Range, and Selection objects has a Sections property that returns a Sections collection containing the Section objects for that parent.

Adding a New Section

To add a new section to a document, range, or selection, use the Add method of the Sections collection. The syntax is:

SectionsObject.Add(Range, Start)

The optional variant parameter Range refers to a Range object before which the section break will be inserted. If this argument is omitted, the section break is inserted at the end of the document. The optional Start parameter indicates the type of section break. It can be any of the following WdSectionStart constants:

	Enum WdSectionStart
	   wdSectionContinuous = 0
	   wdSectionNewColumn = 1
	   wdSectionNewPage = 2
	   wdSectionEvenPage = 3
	   wdSectionOddPage = 4
	End Enum

The default value is wdSectionNewPage.

As an alternative to the Add method, you can insert a new section using the Insert-Break method, which applies to a Range or Selection object. Its syntax is:

expression.InsertBreak(Type)

where expression refers to either a Range or a Selection object, and Type can be any of the following wdBreakType constants:

 Enum WdBreakType wdSectionBreakNextPage = 2 wdSectionBreakContinuous ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required