Determine what type of break is at the end of a page

D

dave.cuthill

I am building a macro that allows a page to be inserted at the end of
the currently select page. Depending on some selections made on a user
form the break may be either a page break or nextpagesection break.

If I insert a nextpage section break all is well and this works fine.
The problem I am having is I need to determine if the page after the
newly inserted page has a page break or a section break at the end of
it in order to determine whether the newly inserted page should have a
section break or page break at its end.

I hope this isn't to confusing

David
 
J

Jean-Guy Marcil

[email protected] was telling us:
[email protected] nous racontait que :
I am building a macro that allows a page to be inserted at the end of
the currently select page. Depending on some selections made on a user
form the break may be either a page break or nextpagesection break.

If I insert a nextpage section break all is well and this works fine.
The problem I am having is I need to determine if the page after the
newly inserted page has a page break or a section break at the end of
it in order to determine whether the newly inserted page should have a
section break or page break at its end.

I hope this isn't to confusing

What you can do is compare the current selection's section index number with
the following page section index number before inserting the page. This way,
if the index number are different, you know there is a section break between
the two pages.

Something like:
curSecindex = Selection.Sections(1).Index
Then create a range that is equal to the current page, move the end of the
range one character (this will include the first character on the next page,
collapse the range, then do
nextSecindex = nextPageRange.Sections(1).Index

If nextSecindex <> curSecindex Then there are two sections involved.

But, you have to be careful. Check first if there is a next page to speak
of! Compare the current page number with the total page count in the
document.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
[email protected]
Word MVP site: http://www.word.mvps.org
 
D

dave.cuthill

Thanks that makes sense - but how do I create a range equal to the
current page?

David
 
D

dave.cuthill

Thanks that makes sense - but how do I create a range equal to the
current page?

David
 
G

Greg Maxey

David,

How about using that predefined bookmark "\Page"

Sub Test()
Dim myRng As Range
Set myRng = ActiveDocument.Bookmarks("\Page").Range
End Sub
 
Top