Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Aug 2004
    Thanked 0 Times in 0 Posts

    Tables in Words... (word 97, word 2000)


    I am creating tables in a Word document using VBA scripts.

    1. How do i determine if a certain table is the first table on a particular page? ( Bascially i want to unset a border i have on the table if it is the first table on a page. )
    2. I do not want the table to be split across pages, so i unchecked the "Allow Row to break across pages" in the Row tab of the Table properties. But, the table still splits across pages.. What am i doing wrong?



  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Tables in Words... (word 97, word 2000)

    2. The "Allow row to break across pages" property applies to individual rows, not to the table as a whole. To keep the table on one page, clear that property for all rows, then select all rows except for the last one, and tick "Keep with next" in the "Line and page breaks" tab of Format | Paragraphs...

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 94 Times in 90 Posts

    Re: Tables in Words... (word 97, word 2000)

    #1 takes a bit of work. VBA doesn't have a handy page object to work with, but you can sort of fake it given the selection and a built-in bookmark. This assumes that you have the table you are working on selected. If not, this might not work at all:
    <pre>Sub Test_IsFirstTableOnPage()
    MsgBox IsFirstTableOnPage(Selection)
    End Sub

    Function IsFirstTableOnPage(sel As Word.Selection) As Boolean
    ' Is the table in which the insertion point resides, or the
    ' first table in the selection, the first table on the page?
    ' If the selection is not in a table, return FALSE
    If (sel.Information(wdWithInTable) = False) And _
    (sel.Tables.Count = 0) Then
    IsFirstTableOnPage = False
    Exit Function
    End If
    ' Use the built-in PAGE bookmark to create a range of the
    ' "current" page (from the beginning of the selection)
    Dim rngTemp As Word.Range
    Set rngTemp = ActiveDocument.Bookmarks("PAGE").Range
    ' Obtain start of range for the first table in the user's
    ' selection, compare with start of range for the first
    ' table in the current page range
    Dim intSelTable As Integer, intFirstTable As Integer
    intSelTable = sel.Tables(1).Range.Start
    intFirstTable = rngTemp.Tables(1).Range.Start
    If intSelTable = intFirstTable Then
    IsFirstTableOnPage = True
    IsFirstTableOnPage = False
    End If
    ' Clean up objects
    If Not (rngTemp Is Nothing) Then Set rngTemp = Nothing
    End Function

    Does it help? (Note: this was tested in Word 2002, but I don't see any reason for it not to work in earlier versions.)

Posting Permissions

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