Class Section (Word VBA)

The class Section represents a single section in a selection, range, or document. The Section object is a member of the Sections collection. The Sections collection includes all the sections in a selection, range, or document.

The main procedure of class Section is Sections.Add

Set

To use a Section class variable it first needs to be instantiated, for example

Dim sec as Section
Set sec = ActiveDocument.Range.Sections(Index:=1)

The following procedures can be used to set variables of type Section: Sections.Add, Sections.Item, Sections.First, Sections.Last, Document.Sections, Range.Sections and Selection.Sections

For Each

Here is an example of processing the Section items in a collection.

Dim sec As Section
For Each sec In ActiveDocument.Range.Sections
	
Next sec

Methods

This is the main method of the Section class

Sections.Add - Returns a Section object that represents a new section added to a document.

Dim sec As Section
Set sec = ActiveDocument.Range.Sections.Add()

Properties

Borders returns a Borders collection that represents all the borders in the section.

ActiveDocument.Range.Sections(1).Borders =

Footers returns a HeadersFooters collection that represents the footers in the specified section.

Dim hfsFooters As HeadersFooters
Set hfsFooters = ActiveDocument.Range.Sections(1).Footers

Headers returns a HeadersFooters collection that represents the headers for the specified section.

Dim hfsHeaders As HeadersFooters
Set hfsHeaders = ActiveDocument.Range.Sections(1).Headers

Index returns a Long that represents the position of an item in a collection.

Dim lngIndex As Long
lngIndex = ActiveDocument.Range.Sections(1).Index

PageSetup returns a PageSetup object that is associated with the specified section.

ActiveDocument.Range.Sections(1).PageSetup =

Parent returns an object that represents the parent object of the specified Section object.

Dim objParent As Object
Set objParent = ActiveDocument.Range.Sections(1).Parent

ProtectedForForms true if the specified section is protected for forms.

ActiveDocument.Range.Sections(1).ProtectedForForms = True

Range returns a Range object that represents the portion of a document that's contained in the specified object.

Dim rngRange As Range
Set rngRange = ActiveDocument.Range.Sections(1).Range

Sections.Count returns a Long that represents the number of sections in the collection.

Dim lngCount As Long
lngCount = ActiveDocument.Range.Sections.Count

Sections.First returns a Section object that represents the first item in the Sections collection.

Dim secFirst As Section
Set secFirst = ActiveDocument.Range.Sections.First

Sections.Last returns the last item in the Sections collection as a Section object.

Dim secLast As Section
Set secLast = ActiveDocument.Range.Sections.Last

Sections.PageSetup returns a PageSetup object that's associated with the specified document, range, section, sections, or selection.

ActiveDocument.Range.Sections.PageSetup =

Sections.Parent returns an object that represents the parent object of the specified Sections object.

Dim objParent As Object
Set objParent = ActiveDocument.Range.Sections.Parent