Select an entire Word Page - one only

Q

quartz

I am automating Word from Excel and I need a sure fire method for selecting
ONE entire page. I have developed the following function, but this sometimes
picks up (or adds) an extra return or two that puts the selection over ONE
page.

Could someone please correct this function so that only ONE page is
selected, or otherwise give me a clue as to what is going on?

Public Function WordSelectPage(argAppRef As Object, argFileName As String,
argPageNumber As Long)
'SELECT A SPECIFIC PAGE IN A WORD DOCUMENT;
argAppRef.Documents(argFileName).Activate
argAppRef.Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext,
Name:=argPageNumber
argAppRef.ActiveDocument.Bookmarks("\Page").Range.Select
End Function

Thanks much in advance.
 
H

Helmut Weber

Hi,
I don't know...
I rather use this method to select a page by page number.
Selection.GoTo _
what:=wdGoToPage, _
which:=wdGoToAbsolute, _
Count:=PageNumber
Note, if there is a manual page break,
seperating the actual page from the next page,
it will be part of the selection.

HTH, I understood your main complaint,
Word would be inserting
additional paragraph marks,
but I've never heard of this and can't reproduce it.
Sorry.
Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
Q

quartz

Thanks Helmut. I figured it out, when you select an entire page it includes
any ending page breaks and/or returns at the end. I can defeat this by having
VBA
"Selection.TypeBackspace" until the document is only one page.

Which leads me to my next question, how do you return the number of pages in
a document?

Thanks again.
 
H

Hari Prasadh

Hi Quartz,

Helmut helped me with no of pages once.... Here it is

Sub textreplaceforpagenumber()
Dim i As Integer
i = Selection.Information(wdNumberOfPagesInDocument)
MsgBox "no of pages is equal to " & i
End Sub

Hope it works in your case.

Thanks a lot,
Hari
India
 
Q

quartz

Thanks to all who responded. Your help has allowed me to complete this
important aspect of a project.

I now have 13 functions that I can call from Excel that automate Word and
can convert a desired page in a Word document into a separate "stand alone"
document. This will eventually be set up so I can call it repeatedly using
arrays to convert entire documents in this manner (if desired).

BTW, this method preserves all formatting of the original document,
including headers and footers. You must however feed the program the page
number that you want each page to contain (this too will be handled in
arrays). The method tests successful for a one section document. If anyone is
interested in a copy, please post back, it may be a little lengthy since I
tend to write most of my code in one-step-at-a-time functions.

Again thanks.
 
R

Richard S.

I am attempting to do a similar procedure, incorporating a Word document into
an Access report. So I would be interested in a copy, believing it would be
analogous.

I greatly appreciate your offer of a copy.

Richard S.
 

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