Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Wed, 18 Jan 2006 08:18:36 -0800,    group: microsoft.public.word.vba.customization        back       


VBA word Table Page   
Hi, 
   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. Thank you. 

Sub CopyTableCell() 
Dim rngPg1 As Word.Range 
Dim rngPg2 As Word.Range 
Dim rngCell1 As Word.Range 
Dim rngCell2 As Word.Range 

'Move to the top of the document 
Selection.HomeKey wdStory 
'Pick up the entire page of the active selection 
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:=2 
'Pick up the entire page 
Set rngPg2 = ActiveDocument.Bookmarks("\Page").Range 
'Pick up the first cell of the second row 
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
date: Wed, 18 Jan 2006 08:18:36 -0800   author:   Ram

Re: VBA word Table Page   
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:23:34 +0100   author:   Cindy M -WordMVP-

Re: VBA word Table Page   
Cindy M -WordMVP- was telling us:
Cindy M -WordMVP- nous racontait que :

> 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

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

-- 
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
date: Thu, 19 Jan 2006 15:08:17 -0500   author:   Jean-Guy Marcil NoSpam@LeaveMeAlone

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

Re: VBA word Table Page   
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: Fri, 20 Jan 2006 18:37:10 +0100   author:   Cindy M -WordMVP-

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

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us