Delete only "next page" section breaks and skip the "continous" section breaks

A

andreas

I recently wrote a macro to delete all section breaks there are in any
document. It is a simple macro and running just fine.
Now, for certain reasons I would like to create a macro that deletes
only the "next page" section breaks, not the other ones, i.e. the
"continuous" section breaks. Can this be achieved somehow?

Help is appreciated. Thanks a lot in advance

Regards,

Andreas
 
D

Doug Robbins - Word MVP

This will convert them all to Continuous Section Breaks

Dim s As Section
For Each s In ActiveDocument.Sections
If s.PageSetup.SectionStart = wdSectionNewPage Then
s.PageSetup.SectionStart = wdSectionContinuous
End If
Next s

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Greg Maxey

Andreas,

This get very tricky due to the way sections work. The following first
converts the break to a continuous section break and then deletes it.
It has not be extensively tested, but might suit your needs:


Sub Testing()
Dim oSection As Section
For Each oSection In ActiveDocument.Range.Sections
Select Case oSection.PageSetup.SectionStart
Case wdSectionNewPage
oSection.PageSetup.SectionStart = wdSectionContinuous
Dim oRng As Word.Range
Set oRng = oSection.Range
oRng.Collapse wdCollapseStart
oRng.Move wdCharacter, -1
oRng.Delete
Case wdSectionOddPage, wdSectionEvenPage, wdSectionContinuous
'Do Nothing
End Select
Next
End Sub
 
A

andreas

Doug,

thanks for the quick answer. I guess, You may have misunderstood my
request. This macro should delete only the "new page" section breaks
and skip the continuous section breaks. Your colleague Greg Maxey
answered as well and his code is working well. Hence my question has
been answered. Nevertheless your code snippet serves me as well for
other macro routines. Thank you!
 
D

Doug Robbins - Word MVP

I figured that you could graft the code that you were using to delete the
sections into the If...then...Else statement.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top