Results 1 to 7 of 7

Thread: Want to know How can I find a Table which flows across the pages in MSWord.[RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Resolved 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.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Want to know How can I find a Table which flows across the pages in MS Word.

    Use the Table collection.
    VB Code:
    1. 'ThisDocument
    2. Option Explicit
    3.  
    4. Private Sub Document_Open()
    5.     Dim oTable As Word.Table
    6.     Set oTable = Documents(1).Tables(1)
    7.     oTable.Cell(2, 1).Range.Text = "Something?"
    8.     Set oTable = Nothing
    9. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Want to know How can I find a Table which flows across the pages in MS Word.

    Quote Originally Posted by RobDog888
    Use the Table collection.
    VB Code:
    1. 'ThisDocument
    2. Option Explicit
    3.  
    4. Private Sub Document_Open()
    5.     Dim oTable As Word.Table
    6.     Set oTable = Documents(1).Tables(1)
    7.     oTable.Cell(2, 1).Range.Text = "Something?"
    8.     Set oTable = Nothing
    9. 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.
    Attached Files Attached Files

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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:
    1. dim oTable As Word.Table
    2. For Each oTable In Documents(1).tables
    3.     oTable.AllowPageBreaks = False
    4.     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:
    1. 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

  5. #5

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Want to know How can I find a Table which flows across the pages in MS Word.

    Quote 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:
    1. dim oTable As Word.Table
    2. For Each oTable In Documents(1).tables
    3.     oTable.AllowPageBreaks = False
    4.     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:
    1. 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.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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:
    1. Dim oTable As Word.Table, f As HeaderFooter, p As PageNumber, s As Section
    2. For Each oTable In Documents(1).tables
    3. '    oTable.AllowPageBreaks = False
    4.     oTable.Rows(1).Cells(1).Select
    5.  
    6.     r = Selection.Information(wdActiveEndPageNumber)
    7.     oTable.Rows(oTable.Rows.Count).Select
    8.     r1 = Selection.Information(wdActiveEndPageNumber)
    9.     If Not r = r1 Then mylist = mylist & r & ","
    10.     Next
    11.     MsgBox "tables run over at the end of the following pages" & vbNewLine & mylist
    12.     Set oTable = Nothing

    pete

  7. #7

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Thumbs up Want to know How can I find a Table which flows across the pages in Word. [RESOLVED]

    Quote 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:
    1. Dim oTable As Word.Table, f As HeaderFooter, p As PageNumber, s As Section
    2. For Each oTable In Documents(1).tables
    3. '    oTable.AllowPageBreaks = False
    4.     oTable.Rows(1).Cells(1).Select
    5.  
    6.     r = Selection.Information(wdActiveEndPageNumber)
    7.     oTable.Rows(oTable.Rows.Count).Select
    8.     r1 = Selection.Information(wdActiveEndPageNumber)
    9.     If Not r = r1 Then mylist = mylist & r & ","
    10.     Next
    11.     MsgBox "tables run over at the end of the following pages" & vbNewLine & mylist
    12.     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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width