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. 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)

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

Borders

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

For information about returning a single member of a collection, see Returning an object from a collection.


ActiveDocument.Range.Sections(1).Borders =

Footers

Returns a HeadersFooters collection that represents the footers in the specified section.

For information about returning a single member of a collection, see Returning an object from a collection. To return a HeadersFooters collection that represents the headers for the specified section, use the Headers property.


With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary) 
 .PageNumbers.Add PageNumberAlignment:=wdAlignPageNumberRight 
End With

Headers

Returns a HeadersFooters collection that represents the headers for the specified section.

For information about returning a single member of a collection, see Returning an object from a collection. To return a HeadersFooters collection that represents the footers for the specified section, use the Footers property.


With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) 
 .PageNumbers.Add _ 
 PageNumberAlignment:=wdAlignPageNumberCenter, _ 
 FirstPage:=False 
End With

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.


Documents("Summary.doc").Sections(1).PageSetup.Gutter = 36

ProtectedForForms

True if the specified section is protected for forms.

When a section is protected for forms, you can select and modify text only in form fields. To protect an entire document, use the Protect method of the Document object.


If ActiveDocument.Sections.Count >= 2 Then _ 
 ActiveDocument.Sections(2).ProtectedForForms = True

Range

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


Set myRange = ActiveDocument.Sections(1).Range 
With myRange 
 .MoveEnd Unit:=wdCharacter, Count:=-1 
 .Collapse Direction:=wdCollapseEnd 
 .InsertParagraphAfter 
 .InsertAfter "End of section" 
End With