Code to access different section breaks

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Code to access different section breaks

Post by ABabeNChrist »

I have a document with mutable section breaks, is there any type of code that I can use to navigate quickly to each section. This document has about 20 section page breaks with about a total of 65 pages so it can take a minute to scroll down the page

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Code to access different section breaks

Post by HansV »

If you want to go to the next section:

Selection.GoTo What:=wdGoToSection, Which:=wdGoToNext

or to the previous section:

Selection.GoTo What:=wdGoToSection, Which:=wdGoToPrevious

To go to a specific section, e.g. the 3rd one in the document:

Selection.GoTo What:=wdGoToSection, Which:=wdGoToAbsolute, Count:=3
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Code to access different section breaks

Post by ABabeNChrist »

Thank you Hans
This will help speed up the process.
By looking at this code I would of never figured this one out

User avatar
StuartR
Administrator
Posts: 12612
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Code to access different section breaks

Post by StuartR »

I assume you are aware that you can navigate to a section from the user interface without using any code at all.

Control-G to get the GoTo dialog box
Select section in the list on the left
Enter the required section number in the text box (or +1 to move forward one section etc.)
OK
StuartR


ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Code to access different section breaks

Post by ABabeNChrist »

Thank you StuartR
For me it works great, for other users, numbers referring to sections maybe confusing. So I decided to use the code that Hans has provided and label each button with a reference name
Again many thanks