Hi =?Utf-8?B?UmFt?=,
> I already posted this before. I thought it was not clear. I am reposting
> it. I am creating a word table using some software. I want to copy last cell
[quoted text clipped - 5 lines]
> My Question is I want to do this repetetively for every page of the table.
> Could you please tell me how to do this on every page.
As you've probably discovered, Word doesn't have a Page object or Pages
collection. so you need to use Selection.GoTo to move from page to page. The
code I gave you moves specifically to page 2, since that's what you asked for.
But you can also tell it to go to the next page:
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext
You'll want to build this into a loop. Since wdGoToNext doesn't throw an error
when you're already on the last page, I'd check the current page number in the
loop. Something like this (untested):
Dim lLastPage as Long, lCurrPage as Long
lCurrentPage = 1
lLastPage = 1
Do
lLastPage = lCurrentPage
'Use Selection.Information(wdActiveEndPageNumber) to
'get the current page number after you GoTo.
'if it's the same as lLastPage, leave the loop
Loop While lLastpage <> lCurrentpage
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
Jean-Guy Marcil - 19 Jan 2006 20:08 GMT
Cindy M -WordMVP- was telling us:
Cindy M -WordMVP- nous racontait que :
> Hi =?Utf-8?B?UmFt?=,
>
[quoted text clipped - 11 lines]
> As you've probably discovered, Word doesn't have a Page object or
> Pages collection. so you need to use Selection.GoTo to move from page
Starting with Word 2003 it does (as well as a Line collection).... It can be
awkward to use, but it is useful, as long as everybody using the document
uses Word 2003, of course
ActiveDocument.ActiveWindow.Panes(1).Pages.Count
ActiveDocument.ActiveWindow.Panes(1).Pages(1).Rectangles(1).Lines.Count

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Ram - 19 Jan 2006 23:42 GMT
Hi,
Thanks for your help. I Actually, I tried using Selection.GoTo
What:=wdGoToPage, Which:=wdGoToNext with a For loop. But somehow its not
going to next page. Its staying in the second page but its pasting the 3rd,
4th pages first cell contents in second page first cell. I will try with the
code that you gave me now. Thank you.
> Hi =?Utf-8?B?UmFt?=,
>
[quoted text clipped - 37 lines]
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)
Cindy M -WordMVP- - 20 Jan 2006 17:37 GMT
Hi =?Utf-8?B?UmFt?=,
> Thanks for your help. I Actually, I tried using Selection.GoTo
> What:=wdGoToPage, Which:=wdGoToNext with a For loop. But somehow its not
> going to next page. Its staying in the second page but its pasting the 3rd,
> 4th pages first cell contents in second page first cell. I will try with the
> code that you gave me now.
Be careful about resetting the RANGE. The code I gave you only uses Selection
to get to a particular page. Then it works relative to a range. So you'll need
to be sure the range is referring to the correct page. From the sound of it,
you need to make sure this are reset when you move to a new page
Set rngPg2 = ActiveDocument.Bookmarks("\Page").Range
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
Ram - 21 Jan 2006 14:46 GMT
Hi,
Its working except for the last page. On the last page, the table can be
just 2 rows, so it might occupy less than first half of the page. I posted
the code already that I am using to do this. If you don't mind could please
check the code and tell me what 's going wrong and What should I do?
> Hi =?Utf-8?B?UmFt?=,
>
[quoted text clipped - 18 lines]
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)
Ram - 20 Jan 2006 02:21 GMT
Hi,
I tried with For Loop. its working except for the last page. Its giving
error 'There is no table at this location'. Here is the my code. If you coud
help what's going wrong and the correction, that would be a lot of help.
Sub copynext()
Dim rngPg1 As Word.Range
Dim rngPg2 As Word.Range
Dim rngCell1 As Word.Range
Dim rngCell2 As Word.Range
numPages = Selection.Information(wdNumberOfPagesInDocument)
'Move to the top of the document
Selection.HomeKey wdStory
'Pick up the entire page of the active selection
For i = 1 To numPages
If i = numPages Then Exit Sub
Selection.GoTo What:=wdGoToPage, Which:=wdGoToPageNumber, Count:=i
Set rngPg1 = ActiveDocument.Bookmarks("\Page").Range
'Pick up the last row, first cell
cellNumber = rngPg1.Rows.Count
Set rngCell1 = rngPg1.Rows(cellNumber).Cells(1).Range
'Shorten the range to drop the end-of-cell marker
rngCell1.MoveEnd wdCharacter, -1
Do Until cellNumber = 1
If rngCell1.Text = "" Then
cellNumber = cellNumber - 1
Set rngCell1 = rngPg1.Rows(cellNumber).Cells(1).Range
rngCell1.MoveEnd wdCharacter, -1
End If
If rngCell1.Text <> "" Then Exit Do
Loop
'Move to the second page
Selection.GoTo What:=wdGoToPage, Which:=wdGoToPageNumber, Count:=i + 1
'Pick up the entire page
Set rngPg2 = ActiveDocument.Bookmarks("\Page").Range
'Pick up the first cell of the second row
'If i < numPages Then Set rngCell2 = rngPg2.Rows(1).Cells(1).Range
Set rngCell2 = rngPg2.Rows(1).Cells(1).Range
'Make sure the range is IN the cell (not containing the cell)
rngCell2.Collapse
'"Copy" the text + formatting
rngCell2.FormattedText = rngCell1.FormattedText
rngCell2.Paragraphs.Alignment = wdAlignParagraphLeft
Next i
Debug.Print rngPg2.Rows.Count, rngCell1.Text
End Sub
> Hi =?Utf-8?B?UmFt?=,
>
[quoted text clipped - 37 lines]
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)
Ram - 26 Jan 2006 16:05 GMT
Hi,
I solved last page of the table jinx by using /cell. Thank you for your
help.
> Hi =?Utf-8?B?UmFt?=,
>
[quoted text clipped - 37 lines]
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)