Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    wdBreakType (Office 2003)

    Good morning loungers
    I am trying to loop through a document selecting ranges defined by nextpage section breaks.
    It seems to me that the -NP- and -C- break types both report character 12 as shown by this loop.

    Sub test_sectnBrk()
    For Each oSectn In ActiveDocument.Sections

    oSectn.Range.Select
    Selection.Collapse Direction:=wdCollapseEnd
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    oSlctd = Selection.Range
    MsgBox (oSlctd)

    Next

    End Sub

    The Word.WdBreakType.wdSectionBreakNextPage constant = 2. How do I pick this up ?
    What am I missing ?
    Thanks in advance.

    Geof

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: wdBreakType (Office 2003)

    Try this:

    Sub TestSectionBreaks()
    Dim sec As Section
    For Each sec In ActiveDocument.Sections
    Debug.Print sec.PageSetup.SectionStart
    Next sec
    Set sec = Nothing
    End Sub

    Output will be in the Immediate window.

  3. #3
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: wdBreakType (Office 2003)

    Hello Hans
    Thanks for the pointer.
    There are some weird happenings here.

    I will preface this by saying / admitting there is not such thing as a blank document.

    I started with a blank document and ran your suggestion, then added (from the menu) -NP- section break, ran the macro, then -C- break and ran the macro.
    Output as follows

    Blank Document output 2
    Insert -NP- sectn brk output 2 2
    Insert -C- sectn Break output 2 2 0

    I was happy enough

    Then I added even page section break and this was reported as 3

    Now the weirdo

    Delete all document contents, ctrl-A, delete

    remaining para identiified as normal style

    Run your macro and the output is now 3.

    There seems to be something weird here concerning the removal of section breaks, ie merging with previous sections.

    Cheers
    Geof

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: wdBreakType (Office 2003)

    This behavior is admittedly confusing. It occurs because the type of break is displayed in the section break before the section, but stored in the section break after the section. There is always an invisible section break at the end of a document, storing the settings of the last section in the document (in a blank document, that is the only section). When you had inserted the three section breaks, the "even page" property was displayed in the 3rd break, but stored in the invisible break at the end. You deleted the three breaks inserted by you, leaving the invisible break set to "even page".

    See MSKB article What happens when you delete a section break.

  5. #5
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: wdBreakType (Office 2003)

    Hi Hans
    Thanks for your help.
    The following loop will be the basis for my solution,, I think.
    The key was the distinction between the sections which display and store the break format..

    Once again thanks and cheers.
    Geof

    Sub DocumentSplit()
    On Error Resume Next
    Application.ScreenUpdating = False
    Set oRa = ActiveDocument.StoryRanges(wdMainTextStory)

    For a = 1 To oRa.Sections.Count
    oRa.Sections(a).Range.Select

    If oRa.Sections(a + 1).PageSetup.SectionStart = 2 Then
    Selection.Collapse Direction:=wdCollapseEnd
    Selection.HomeKey unit:=wdStory, Extend:=wdExtend
    Selection.Copy
    Selection.Delete
    Application.Documents.Add
    Selection.Paste

    End If
    Next

    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •