Class Sections (Word VBA)

A collection of Section objects in a selection, range, or document. To use a Sections class variable it first needs to be instantiated, for example


Dim scts as Sections
Set scts = ActiveDocument.Range.Sections

For Each

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


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

Add

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

Add (Range, Start)


Set myRange = ActiveDocument.Paragraphs(3).Range 
ActiveDocument.Sections.Add Range:=myRange

Arguments

Optional arguments

The following arguments are optional

Range (Range) - The range before which you want to insert the section break. If this argument is omitted, the section break is inserted at the end of the document.

Start (WdSectionStart) - The type of section break you want to add. Can be one of the WdSectionStart constants. If this argument is omitted, a Next Page section break is added.


Possible values are

wdSectionContinuous Continuous section break.
wdSectionEvenPage Even pages section break.
wdSectionNewColumn New column section break.
wdSectionNewPage New page section break.
wdSectionOddPage Odd pages section break.

Count

Returns a Long that represents the number of sections in the collection.


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

First

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


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

Item

Returns an individual Section object in a collection.

Item (Index)

Index: The individual object to be returned. Can be a Long indicating the ordinal position of the individual object.


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

Last

Returns the last item in the Sections collection as a Section object.


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

PageSetup

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


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