
Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
Thanks for the reply. I have removed the ActiveDocument.ActiveWindow part,
and it works as it did before. Can I do the same thing with
ActiveDocument.Bookmarks? Does it matter if the code is in an Add-In?
I may not have explained clearly, but here's the distinction I am making:
When I open a document the cursor is blinking at the very beginning of the
document. If I scroll to page 2, click Print, and choose to print the
current page, page 2 will print. However, if I do:
Dim lngPage as Long
lngPage = Selection.Range.Information(wdActiveEndAdjustedPageNumber)
lngPage will return "1", apparently because the insertion point remained on
page 1 even as I scrolled to page 2.
I am working on quite a number of documents, and have set up the message box
to test that I am printing the intended pages rather than actually printing
them. I have just realized I can print the current page using code no
matter where the cursor is located, so the fact that the message box shows
the "wrong" page number is in one sense not very important, but for other
reasons I would like to be able to obtain the number. The instruction to
print the current page:
ActiveDocument.PrintOut Range:=wdPrintCurrentPage
"knows" which page is visible on the screen. However, the following:
Dim lngPage as Long
lngPage = Selection.Range.Information(wdActiveEndAdjustedPageNumber)
returns the page where the insertion point is located as lngPage.
I work quite a lot with VBA Access, but the world of Word VBA is still
rather mysterious to me. Being unable to assign to a variable the page
number of the page currently in view is a minor problem, but I would like to
solve it anyhow, if possible.
BTW, I will be leaving work soon for the day, and will not return until
Monday. I may not have a chance to check the newsgroups, so if you reply
and I do not acknowledge it at first, please don't think me rude.
>> I have some code that is designed to print certain pages from a
>> document. The general idea is that the user will select a page, which
[quoted text clipped - 15 lines]
> a page and "going to" a page. Either way, the Selection points to that
> page, so it shouldn't make any difference how it got there.
Jay Freedman - 14 Dec 2007 03:18 GMT
>Thanks for the reply. I have removed the ActiveDocument.ActiveWindow part,
>and it works as it did before. Can I do the same thing with
>ActiveDocument.Bookmarks? Does it matter if the code is in an Add-In?
No. The Selection object is a property of the Application object (that
is, all of Word can have only one Selection at any time), and VBA lets
you omit the "Application." part for any of the Application's members.
That isn't true for bookmarks, as each document has its own Bookmarks
collection. So you do have to spell out ActiveDocument.Bookmarks (or,
if you've declared and assigned some other Document object, you can
then write something like MyDoc.Bookmarks).
>I may not have explained clearly, but here's the distinction I am making:
>When I open a document the cursor is blinking at the very beginning of the
[quoted text clipped - 22 lines]
>
>returns the page where the insertion point is located as lngPage.
Ahah, that is different. Unfortunately there are quite a few things in
the user interface of Word that VBA knows nothing about and can't
duplicate. Knowing the page number of a visible page when the
insertion point is somewhere else is one of those things. If for some
reason wdPrintCurrentPage isn't sufficient, then you're going to have
to click on a page to get the Selection to be there.
>I work quite a lot with VBA Access, but the world of Word VBA is still
>rather mysterious to me. Being unable to assign to a variable the page
[quoted text clipped - 24 lines]
>> a page and "going to" a page. Either way, the Selection points to that
>> page, so it shouldn't make any difference how it got there.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
BruceM - 17 Dec 2007 12:43 GMT
Thanks for the information. I understand the distinction you are making
between Selection, which can apply to one document only, and the bookmarks
collection, which is document-specific.
Thanks too for the information about VBA "knowing" which page is current. I
suspected as much. It seems a curious thing that VBA can be used can
identify the current page for printing purposes, but can't tell anybody the
page number, but at least now I can stop looking for a way to do that. It
would have been mildly helpful, but it really doesn't matter. If it does,
the user will just have to click the page. It still would be a big
improvement over the way things are done now.
>>Thanks for the reply. I have removed the ActiveDocument.ActiveWindow
>>part,
[quoted text clipped - 84 lines]
> Email cannot be acknowledged; please post all follow-ups to the newsgroup
> so all may benefit.