Want to know How can I find a Table which flows across the pages in MSWord.[RESOLVED]
Hi all,
How can I find a table which flows across the pages?
For example,
I have a table with about 50 rows. 20 rows are coming in first page (the table starts in middle of first page) and the rest of the rows are coming in second page. There are about 30 tables in the document. on that about 7 tables flows across the pages. So, If the user runs a macro, the macro should go to the particular table that flows across the pages. So that, the user can change the way of flow and fit it in a single page.
What type of coding will work out for that?
Thanks,
CS.
Last edited by cssriraman; Jun 15th, 2005 at 10:25 AM.
Re: Want to know How can I find a Table which flows across the pages in MS Word.
Originally Posted by RobDog888
Use the Table collection.
VB Code:
'ThisDocument
Option Explicit
Private Sub Document_Open()
Dim oTable As Word.Table
Set oTable = Documents(1).Tables(1)
oTable.Cell(2, 1).Range.Text = "Something?"
Set oTable = Nothing
End Sub
Hi, Thank you for your reply. the code which you give adds/modifies the content of the table 1 row 2 column1 cell to "Something?" text. My requirement is not that. I don't like to add/modify any content. Please see the attached Word Document. Pls View that document in Print Layout View. The document contains about 5 tables. Please look out the table no.5 which has problems. That is, In that Table, some of the rows are coming in Page 5 an some of the rows are coming in page 6. So, I would like to find those table which flows across the pages. How can I do that? Pls update. Thanks, CS.
Re: Want to know How can I find a Table which flows across the pages in MS Word.
i just copied rob's code into your document, extended table one to the second page, the used the table property allowpagebreaks= false to force it onto the next page, of course this left a big gap at the bottom of page 1
to make the code work for all tables you can loop through the tables collection
VB Code:
dim oTable As Word.Table
For Each oTable In Documents(1).tables
oTable.AllowPageBreaks = False
Next
which then also put table on page 5 onto a new page
if you just wish the user to goto the top or bottom of a table
VB Code:
oTable.Rows(oTable.Rows.Count).Select
for the last row of the table,
but as yet i haven't figured out how to tell which page the first and last row are on, to know if they are different, probably have to get the page number out of the footer
Re: Want to know How can I find a Table which flows across the pages in MS Word.
Originally Posted by westconn1
i just copied rob's code into your document, extended table one to the second page, the used the table property allowpagebreaks= false to force it onto the next page, of course this left a big gap at the bottom of page 1
to make the code work for all tables you can loop through the tables collection
VB Code:
dim oTable As Word.Table
For Each oTable In Documents(1).tables
oTable.AllowPageBreaks = False
Next
which then also put table on page 5 onto a new page
if you just wish the user to goto the top or bottom of a table
VB Code:
oTable.Rows(oTable.Rows.Count).Select
for the last row of the table,
but as yet i haven't figured out how to tell which page the first and last row are on, to know if they are different, probably have to get the page number out of the footer
pete
Hi, Your code changes the property allowpagebreaks=false of all tables so that the table will not flow across the pages at the same time, as you said, this left big gap at the bottom of the page. In my case, the user don't want to do anything automatically. If the user runs a macro, the macro should point out the table which flows across pages. At the same time, it should not change any property/content. the user will decide what he has to do with that table? whether he needs to fit it on the previous page by reducing the font size or something else? or move that table to next page and fill some text if needed in the previous page. Thanks! CS.
Re: Want to know How can I find a Table which flows across the pages in MS Word.
here is the code to tell you if the tables are on the same pages or not, but it will take quite a bit more to make a smooth thing as once you cange the tables, it will change the document layout, this will just give the page numbers that have a table split in a messagebox, but for some reason if one line of a table is at the bottom of a page it reads the next page number, 2 lines is fine
VB Code:
Dim oTable As Word.Table, f As HeaderFooter, p As PageNumber, s As Section
For Each oTable In Documents(1).tables
' oTable.AllowPageBreaks = False
oTable.Rows(1).Cells(1).Select
r = Selection.Information(wdActiveEndPageNumber)
oTable.Rows(oTable.Rows.Count).Select
r1 = Selection.Information(wdActiveEndPageNumber)
If Not r = r1 Then mylist = mylist & r & ","
Next
MsgBox "tables run over at the end of the following pages" & vbNewLine & mylist
Want to know How can I find a Table which flows across the pages in Word. [RESOLVED]
Originally Posted by westconn1
here is the code to tell you if the tables are on the same pages or not, but it will take quite a bit more to make a smooth thing as once you cange the tables, it will change the document layout, this will just give the page numbers that have a table split in a messagebox, but for some reason if one line of a table is at the bottom of a page it reads the next page number, 2 lines is fine
VB Code:
Dim oTable As Word.Table, f As HeaderFooter, p As PageNumber, s As Section
For Each oTable In Documents(1).tables
' oTable.AllowPageBreaks = False
oTable.Rows(1).Cells(1).Select
r = Selection.Information(wdActiveEndPageNumber)
oTable.Rows(oTable.Rows.Count).Select
r1 = Selection.Information(wdActiveEndPageNumber)
If Not r = r1 Then mylist = mylist & r & ","
Next
MsgBox "tables run over at the end of the following pages" & vbNewLine & mylist
Set oTable = Nothing
pete
Thank you so much! It works fine!
Thanks a Lot! once Again!
CS.
Last edited by cssriraman; Jun 15th, 2005 at 09:53 AM.