Solved

Check whether section breaks exist

Posted on 2010-11-17
2
571 Views
Last Modified: 2012-06-21
Dear Experts:

I would like a macro to check the following on the current multipage document:

Check whether ...
... at the end of page 1 a section break exists (either section break 'new page' or section break 'even page').
If none of these type of section breaks exists on page 1 the macro is to say so in a MsgBox and is to exit

If such a section break exists on page 1 the macro is to go on and check whether ...
... at the end of the penultimate page an 'even page' or a 'new page' section break exists.
If neither of these section breaks exist on the penultimate page the macro is to say so in a MsgBox and is to exit.

I have attached a sample for your convenience.

Thank you very much in advance for your professinal help.

Regards, Andreas  SectionBreaks-Macro.docx SectionBreaks-Macro.docx
0
Comment
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 34163395
Hi Andreas.

That is a bit trickier than it looks at first sight - see the comment.
Sub CheckSectionStarts()
    Dim bFirst As Boolean
    Dim bLast As Boolean
    
    Selection.GoTo wdGoToPage, wdGoToAbsolute, 2
    If Selection.Sections(1).Index = 2 Then
        Select Case ActiveDocument.Sections(2).PageSetup.SectionStart
            Case wdSectionEvenPage, wdSectionNewPage
                    bFirst = True
            Case Else
        End Select
    End If
    
    If bFirst Then
        Selection.GoTo wdGoToPage, wdGoToAbsolute, Selection.Information(wdNumberOfPagesInDocument) - 1
        'next line checks that penultimate page is not an empty page created by a break on the previous page
        If Selection.Information(wdActiveEndPageNumber) = Selection.Information(wdNumberOfPagesInDocument) - 1 Then
            Select Case ActiveDocument.Sections.Last.PageSetup.SectionStart
                Case wdSectionEvenPage, wdSectionNewPage
                        bLast = True
                Case Else
            End Select
        End If
    End If
    
    If bFirst Then
        If Not bLast Then
            MsgBox "The penultimate page does not end with a New or an Even Page section break"
        End If
    Else
        MsgBox "Page 1 does not end with a New or an Even Page section break"
    End If
End Sub

Open in new window

0
 

Author Closing Comment

by:AndreasHermle
ID: 34164810
Dear Graham,

it sure looks complicated. Thank you very much for your superb help. Exactly as I wanted it. I works just great!

Regards, Andreas
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question