How to find the type of all the section breaks in a word document using macros RRS feed

  • Question

  • Hi,

    I need to find all the section break and remove the section break "continuous" from a word document using VBA. Thanks in Advance!


    Monday, October 22, 2012 2:51 PM

All replies

  • Here is a macro you can use. Credit goes to Doug Robbins, I think.

    Sub RemoveContinuousSectionBreaks()
        Dim i As Long
        Dim rng As Range
        Application.ScreenUpdating = False
        For i = ActiveDocument.Sections.Count To 2 Step -1
            If ActiveDocument.Sections(i).PageSetup.SectionStart = wdSectionContinuous Then
                ActiveDocument.Sections(i).PageSetup.SectionStart = _
                    ActiveDocument.Sections(i - 1).PageSetup.SectionStart
                Set rng = ActiveDocument.Sections(i - 1).Range
                rng.End = rng.End - 1
                rng.Collapse Direction:=wdCollapseEnd
            End If
        Next i
        Application.ScreenUpdating = True
    End Sub

    Regards, Hans Vogelaar

    Monday, October 22, 2012 3:22 PM
  • Hi Hans,

    Thanks for your time. BTW, I have already tried this, but it works only to some extent, i.e., it skips if a section break "continuous" occurs either in start of a page, or in the end of a page.


    Wednesday, October 24, 2012 5:13 AM
  • Strange. The macro works for me regardless of the position of the continuous section breaks.

    Regards, Hans Vogelaar

    Wednesday, October 24, 2012 5:52 AM
  • Hans,

    I'm extremely sorry but it doesn't work for me. I've tried something close to this before I started this thread, and I tried your code too, but the result was the same. Kindly advice me.


    Friday, October 26, 2012 11:37 AM
  • Sorry, no idea.

    Regards, Hans Vogelaar

    Friday, October 26, 2012 11:41 AM