|
|
|
date: Wed, 18 Jan 2006 08:18:36 -0800,
group: microsoft.public.word.vba.customization
back
Re: VBA word Table Page
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.
"Cindy M -WordMVP-" wrote:
> 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
> > content of first column on first page and copying into second cell of first
> > column on second page. I got an answer from a MVP about how to do this.
> > Thanks to her. I extended it to copy last non empty cell content of first
> > column and paste it into the second page second cell of first column. Here is
> > the code that I modified.
> > 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 :-)
>
>
date: Thu, 19 Jan 2006 15:42:02 -0800
author: Ram
VBA word Table Page
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
"Cindy M -WordMVP-" wrote:
> 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
> > content of first column on first page and copying into second cell of first
> > column on second page. I got an answer from a MVP about how to do this.
> > Thanks to her. I extended it to copy last non empty cell content of first
> > column and paste it into the second page second cell of first column. Here is
> > the code that I modified.
> > 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 :-)
>
>
date: Thu, 19 Jan 2006 18:21:01 -0800
author: Ram
VBA word Table Page
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?
"Cindy M -WordMVP-" wrote:
> 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 :-)
>
>
date: Sat, 21 Jan 2006 06:46:02 -0800
author: Ram
VBA word Table Page
Hi,
I solved last page of the table jinx by using /cell. Thank you for your
help.
"Cindy M -WordMVP-" wrote:
> 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
> > content of first column on first page and copying into second cell of first
> > column on second page. I got an answer from a MVP about how to do this.
> > Thanks to her. I extended it to copy last non empty cell content of first
> > column and paste it into the second page second cell of first column. Here is
> > the code that I modified.
> > 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 :-)
>
>
date: Thu, 26 Jan 2006 08:05:04 -0800
author: Ram
|
|