When to Page Break?

M

Mark Loveless

I'm writing a report with tables on a page, like so

Completed items (table 1)
a
b
c
d

Active Items (table 2)
e
f
g
h

Open Items (table 3)
i
j
k

What this old COBOL hack expects is a property somewhere that tells me
where I am on the page at new table write time (say 6.125 inches
down). I know how many rows are going to be generated in my table
(from the .RecordCount of the query of, say, Open Items), so with the
vertical position I can make an educated guess as to whether to page
break to get all the table on a single page (these tables of items
range from 0 to about 40 single-line rows). This break is not
essential, by any means, but would help readability.

I believe, however, that I have a mindset problem - the Word Object
Model doesn't appear to work that way, or more correctly, if there is
such a way I can't find a documentation reference to it at MSDN
Knowledge Base. Word knows the position when keying manually (I can
see the numbers), but I can't find how to access that info.

Is this a doable thing? Having this information (both vertical and
horizontal position of the next Insert point) would be extremely
useful; I have another instance in which I'd like to tab over to 5
1/2", but I don't have the current horizontal position to determine
how many tab stops 5 1/2" is ahead of my current position. If this is
not doable in a position-aware manner, is there a Model-consistent way
of accomplishing the same outcome?

Any help would be greatly appreciated. TIA.

Mark Loveless
Reluctant Access Programmer
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Mark Loveless > écrivait :
In this message, < Mark Loveless > wrote:

|| I'm writing a report with tables on a page, like so
||
|| Completed items (table 1)
|| a
|| b
|| c
|| d
||
|| Active Items (table 2)
|| e
|| f
|| g
|| h
||
|| Open Items (table 3)
|| i
|| j
|| k
||
|| What this old COBOL hack expects is a property somewhere that tells me
|| where I am on the page at new table write time (say 6.125 inches
|| down). I know how many rows are going to be generated in my table
|| (from the .RecordCount of the query of, say, Open Items), so with the
|| vertical position I can make an educated guess as to whether to page
|| break to get all the table on a single page (these tables of items
|| range from 0 to about 40 single-line rows). This break is not
|| essential, by any means, but would help readability.
||
|| I believe, however, that I have a mindset problem - the Word Object
|| Model doesn't appear to work that way, or more correctly, if there is
|| such a way I can't find a documentation reference to it at MSDN
|| Knowledge Base. Word knows the position when keying manually (I can
|| see the numbers), but I can't find how to access that info.

If I understand correctly, you need two things here.
You need the actual page position AND the approximate length of the next
table to see if it will fit on the available space between the cursor and
the bottom margins

Once you now how many rows you will need (and assuming the rows are all of
the same height), you can get the position with:

Round(PointsToInches(Selection.Information(wdVerticalPositionRelativeToPage)
), 2)
Then you need to do some maths to subtract the bottom margin to get the
actual available space:

'_______________________________________
Const RoundNumber As Long = 2
Const PageLength As Single = 11.5
Dim MyBotMargin As Single
Dim MyPosition As Single
Dim SpaceLeft As Single

MyBotMargin = Round(PointsToInches(PageSetup. _
BottomMargin), RoundNumber)

MyPosition = Round(PointsToInches(Selection. _
Information(wdVerticalPositionRelativeToPage)), RoundNumber)

SpaceLeft = PageLength - (MyPosition + MyBotMargin)
MsgBox SpaceLeft
'_______________________________________

||
|| Is this a doable thing? Having this information (both vertical and
|| horizontal position of the next Insert point) would be extremely
|| useful; I have another instance in which I'd like to tab over to 5
|| 1/2", but I don't have the current horizontal position to determine
|| how many tab stops 5 1/2" is ahead of my current position. If this is
|| not doable in a position-aware manner, is there a Model-consistent way
|| of accomplishing the same outcome?

Try something like:

'_______________________________________
Dim myPosition As Single
Const RoundNumber As Long = 2

myPosition = Round(PointsToInches(Selection. _
Information(wdHorizontalPositionRelativeToTextBoundary)), RoundNumber)

If myPosition < 5.5 Then
With Selection.ParagraphFormat.TabStops
.ClearAll
.Add Position:=InchesToPoints(5.5), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
End With

Selection.TypeText Text:=vbTab
End If
'_______________________________________

This will clear all tab stops and set a single tab stop at the desired
position. Otherwise, you have to count how many tab stops there are and if
none are set, check the default tab stop position and figure out how many
you would need. Sounds kind of complicated!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
V

Veronica Brown

Another approach might be to use the styles in your Word Template so that
all text in the table has "Keep with Next" turned on. Then put an empty
paragraph between tables, with "Keep with Next" turned off, so that word has
a place to break.)

Then, let Word do what you are trying to do in your macro.

This feature is in Format > Paragraph >Line and Page Breaks tab. You will
want to build it into a Style, and then use the macros to apply that style
only to your text inside the tables.

Hope this helps...!
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Veronica Brown > écrivait :
In this message, < Veronica Brown > wrote:

|| Another approach might be to use the styles in your Word Template so that
|| all text in the table has "Keep with Next" turned on. Then put an empty
|| paragraph between tables, with "Keep with Next" turned off, so that word
has
|| a place to break.)
||
|| Then, let Word do what you are trying to do in your macro.
||
|| This feature is in Format > Paragraph >Line and Page Breaks tab. You
will
|| want to build it into a Style, and then use the macros to apply that
style
|| only to your text inside the tables.
||

That is indeed a very painless way of doing this.

Just thought I'd point out a little-mini "drawback" with this:
Let's say you have a very short table at the top of the first page that
leaves you with 90% of the space available on the page. Then, the next
table is just a bit too long to fit on one page, so it doesn't matter what
you do, it will have to be fitted on two pages. In such a case (Using "Keep
with next"), Word moves the beginning of the second table at the beginning
of page two, leaving you with a very large blank space on the first page.

I guess you could fix those few cases by hand (Remove the "Keep with next"
for those tables). Or, with a macro, calculate the space needed for the
table to be inserted, and if it is longer than a page either do not insert a
page break (your first idea) or remove the "Keep with next" attribute after
inserting it (Veronica's suggestion).

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

Mark Loveless

Many thanks! Selection.Information was the key to the puzzle - I
couldn't figure out how to determine my current position on the page.
Everything else flows pretty easily from that.

Merci beaucoup!
 

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