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.