VBA Code


Removing Section Breaks

After running these lines of code the whole document will be selected.

With ActiveDocument.Content.Find 
   .Text = "^b"
   .Replacement.Text = ""
   .Execute Replace:=wdReplace.wdReplaceAll
End With


The section object represents a section in a document, range or selection
Each of the Document, Range and Selection objects has a Sections property that returns a sections collection.

objSectionsCol = ObjDocument.Sections 


The Range parameter refers to the range before which the section break will be inserted
The Start is the type of section break to insert

objSection.Add Range:=Start:=wdSectionStart.wdSectionContinuous 

An alternative way to insert a new section is using the InsertBreak method which applies to a Range or Selection object


expression.InsertBreak(wdBreakType.wdSectionBreakNextPage) 

When you insert a section break it is inserted immediately before the specified range or selection
However for the other types of breaks the range or selection is actually replaced


The Sections collection has a PageSetup property that returns a PageSetup object.
These settings are only accurate for all the settings that are common to all the sections in the sections collection.


objPageSetup.SectionStart = wdSectionStart.wdSectionNewPage 


First and Last

ActiveDocument.Sections.Item(1) 
ActiveDocument.Sections.First

ActiveDocument.Sections.Item(ActiveDocument.Sections.Count) 
ActiveDocument.Sections.Last



Get the Index number of the current section

Define a range from the start of the document to the end of the first selected paragraph

Msgbox (ActiveDocument.Range(0,Selection.Paragraphs(1).Range.End).Sections.Count) 



© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrev