Macro to move to bottom of any page

  • Thread starter lots of questions
  • Start date
L

lots of questions

When creating word templates in 2003, I often record a macro that jumps to
the bottom of the last page, inserts a section break, new page and proceeds
with the routine.

This is what I am currently using to accomplish the goal..

Sub AddPage()
'
' NewPage2 Macro
' Macro recorded 10/17/00 by ic06504
'
Application.ScreenUpdating = False
ActiveDocument.Tables(1).Select
Selection.Copy
Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdPageBreak
Selection.Paste
Selection.EndKey Unit:=wdStory
Selection.Tables(1).Select
Selection.Cells.Merge
Selection.Cells.SetHeight RowHeight:=426, HeightRule:=wdRowHeightExactly
Selection.Tables(1).Select
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Collapse
Application.ScreenUpdating = True

End Sub

Am assuming that the "wdStory" is taking me to the bottom of the last page
in the document. How can I write the code to go to the bottom of any page
and do the same thing. There are forms that I need to insert pages between
existing pages. I've looked and can't find exactly what I am looking
for.....any assistance is always appreciated
 
B

bev thomas

Don't know if there is any direct way to get to the bottom of a
specific page, but perhaps this might help. Suppose you want to get
to the bottom of page 4, you maybe could use:

Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="5"
Selection.MoveLeft Unit:=wdCharacter, Count:=1
 
C

Charles Kenyon

Just some thoughts for Bev Thomas (whose post doesn't appear in my OE for
some reason):

Thought 1 - Pages vs. Logical breaks

Pages are really not a concept that fits well in Word documents, because
pages will be cut and flow to fit a particular printer at print time. Manual
page breaks and insertion of next-page section breaks can make a hash of an
otherwise well-formatted document in short order. Going to the end of a
document, on the other hand is a relatively simple operation.

You want to be inserting your new material at a logical insertion point. You
are seeing this as being at the end of your current page. Doing this
automatically is likely to mess up your document. Look, instead, to
inserting before the beginning of the next instance of Heading 2 or Heading
1 style.

Thought 2 - Ranges v Selection point

Selection.EndKey Unit:=wdStory

The above moves the insertion point to the end of the document. It is a
recorded statement, with the drawbacks that accompany recorded statements.
Often you do not want to move the insertion point, you simply want to do
something at a given point. If this is the situation, you need to study the
difference between the selection point and a range.
http://word.mvps.org/FAQs/MacrosVBA/index.htm

--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
H

Helmut Weber

Hi,

how about this one,
which should work even on the last page.

Sub test000234()
Dim rTmp As Range
Set rTmp = Selection.Bookmarks("\page").Range
rTmp.End = rTmp.End - 1
rTmp.Collapse direction:=wdCollapseEnd
rTmp.Select
End Sub

Beware of tables spanning over the pages end.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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