Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2006

Tip: Looking for answers? Try searching our database.

Macro to move to bottom of any page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lots of questions - 02 Mar 2006 23:29 GMT
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
bev thomas - 03 Mar 2006 18:59 GMT
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

>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
[quoted text clipped - 29 lines]
>existing pages.  I've looked and can't find exactly what I am looking
>for.....any assistance is always appreciated
Charles Kenyon - 03 Mar 2006 19:52 GMT
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

Signature

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

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
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.

> 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
[quoted text clipped - 39 lines]
>>existing pages.  I've looked and can't find exactly what I am looking
>>for.....any assistance is always appreciated
Helmut Weber - 03 Mar 2006 20:03 GMT
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.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.