![]() |
|
#1
|
|||
|
|||
|
Hi guys,
I am using the following code to select between headings for each page at once (not for the whole document). Is there a way to select between headings excluding the section break which I have at the end of each page? The structure of all my pages is as follows: Page 1: Heading Text Section break Page 2: Heading Text Section break Code:
Sub selectbetweenheadings()
'
' selectbetweenheadings Macro
'
'
Dim p As Paragraph
Dim i As Long
Dim reverseFlag As Boolean
reverseFlag = True
'Move the selection forward one paragraph
'Assumption: The entire first heading paragraph is selected.
'If not, you'll need to move forward 2.
If Selection.MoveEnd(wdParagraph, 1) = 1 Then
Do
i = Selection.Paragraphs.Count
Set p = Selection.Paragraphs(i)
If Left(p.style, 7) = "Heading" Then Exit Do
'Paragraph is not a heading. try the next one
If Selection.MoveEnd(wdParagraph, 1) = 0 Then
'We're at the end of the document
reverseFlag = False
Exit Do
End If
Loop
End If
If reverseFlag Then Selection.MoveEnd wdParagraph, -1
End Sub
Last edited by macropod; 06-20-2021 at 04:51 PM. Reason: Added code tags |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Next Page Section Break somehow changed to Cont. Section Break; each time fix spreads to prev chap
|
Swarup | Word | 10 | 02-15-2021 06:46 PM |
Word 2007, cannot insert Section Break (Continuous), only Section Break (Next Page)
|
btse1 | Word | 3 | 11-01-2018 09:23 AM |
| Section Break (Continuous) counted as Section Break (Next page) | wolfer | Word VBA | 2 | 01-06-2018 09:51 AM |
Word converts section break to page break before columns, does not insert column breaks
|
eborda | Word | 1 | 03-24-2017 11:06 PM |
Section Break (Next Page) replaces Section Break (Continuous) when deleted
|
Carlabasson | Word | 2 | 03-25-2013 10:13 PM |