Jump to a page, then select all the text on THAT page only

J

John

Hi.

I want to use Control-F to just to a specific page. When I arrive at
that page, i want to copy all the text on that page only. It's
possible to do by manually, not sure if it can be done using a macro.
(if only there was a control-A that applied just to that one page)
 
G

Graham Mayor

ActiveDocument.Bookmarks("\page").Range.Copy

will copy the text of the current page to the clipboard, however a 'page' is
a vague concept in Word and comprises of several elements. It may not be
possible to copy all those elements together, so how successful this will be
depends on what is on the 'page'.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

John

ActiveDocument.Bookmarks("\page").Range.Copy

will copy the text of the current page to the clipboard, however a 'page'is
a vague concept in Word and comprises of several elements. It may not be
possible to copy all those elements together, so how successful this willbe
depends on what is on the 'page'.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>







- Show quoted text -

To Graham,

It worked. Thanks so much. You are awesome. You've made my day. :)


To the whole group,

Is there some code I can add to the end of that, to make it switch to
the open document "C.doc" and then pasting into that document. (I will
position the cursor at the end of C.doc as I assume it will paste at
the point where the cursor is)
 
G

Graham Mayor

See the reply to your other thread.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


ActiveDocument.Bookmarks("\page").Range.Copy

will copy the text of the current page to the clipboard, however a 'page'
is
a vague concept in Word and comprises of several elements. It may not be
possible to copy all those elements together, so how successful this will
be
depends on what is on the 'page'.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>







- Show quoted text -

To Graham,

It worked. Thanks so much. You are awesome. You've made my day. :)


To the whole group,

Is there some code I can add to the end of that, to make it switch to
the open document "C.doc" and then pasting into that document. (I will
position the cursor at the end of C.doc as I assume it will paste at
the point where the cursor is)
 
J

John

ActiveDocument.Bookmarks("\page").Range.Copy

will copy the text of the current page to the clipboard, however a 'page'is
a vague concept in Word and comprises of several elements. It may not be
possible to copy all those elements together, so how successful this willbe
depends on what is on the 'page'.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>







- Show quoted text -

Now that I have the answer, it's great, but I'd like to try and teach
myself what

ActiveDocument.Bookmarks("\page").Range.Copy

means. Step-by-step. Can anyone recommend any books/video tutorials
where I can learn the basics of Visual Basic. I imagine it's a very
steep learning curve!

Regards
 
J

Jay Freedman

John said:
Now that I have the answer, it's great, but I'd like to try and teach
myself what

ActiveDocument.Bookmarks("\page").Range.Copy

means. Step-by-step. Can anyone recommend any books/video tutorials
where I can learn the basics of Visual Basic. I imagine it's a very
steep learning curve!

Regards

Hi John,

Start at http://www.word.mvps.org/FAQs/MacrosVBA/VBABasicsIn15Mins.htm. Also
look at some of the other articles listed in
http://word.mvps.org/FAQs/MacrosVBA.htm#BeginnersTips, and
http://www.gmayor.com/installing_macro.htm.

Let's take apart the current example,
ActiveDocument.Bookmarks("\page").Range.Copy:

- The keyword "ActiveDocument" means the Word document that currently has
the focus (that is, where the letters would go if you started typing). If
you have two or more documents open at the same time, ActiveDocument might
refer to different documents at different times, even during a single macro
run.

- The period or dot should be read as "contains" or "has as a property or
method".

- In this case, the ActiveDocument contains a Bookmarks collection -- a list
of all the bookmarks in that document.

- The quoted string in parentheses is an "index" or identifier that chooses
a single bookmark out of the Bookmarks collection. In this case, "\page" is
a built-in bookmark (that is, you don't have to define it manually) that
covers the contents of the page that contains the cursor (technically, the
Selection object) at the time this command executes. As Graham said, this is
a vague concept in Word because the page contents are constantly being
recomputed on the basis of the text in the document, its formatting, the
margins and orientation, graphics, manual breaks, etc. etc. and how the
currently selected printer driver interprets all of that.

Recapping, up to this point ActiveDocument.Bookmarks("\page") gets us a
bookmark in the right location.

- After the next dot, the Range keyword refers to an object defined by the
location (starting and ending points) of the bookmark. The Range object has
a ton of properties and methods for formatting and manipulating the text.
It's worth opening the VBA help topic on the Range object and looking at the
list of its members, and reading about any that seem interesting.

- The last dot and the Copy keyword refer to the command to copy the
contents of the page to the clipboard.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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