Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: Table Width

  1. #1
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Table Width (preferredwidth) as 7 nines? (XP)

    The 9999999 value indicates "undefined" which often means "not just one." In playing around, I'm able to get this result in the following manner: create two tables, set a preferred width for one of them, delete the paragraph marks separating the tables. Even after separating the noncompliant rows and resetting the preferred width to various things, I can't seem to get VBA to give me a real value for the original table that did not have a preferred width.

    Not sure this helps. I don't do much VBA/Table size stuff (I generally preformat them, save as AutoText, and insert them).

  2. #2
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Table Width (preferredwidth) as 7 nines? (XP)

    Well, what I really need is not the *preferred* width, but the actual width of the table (I'm writing an auditing tool, that among other things will check for stuff outside of margins).

    It bugs me that the GUI "knows" the width, but the programming interface won't give it to me.

    By the way... is there an Office/Word symbolic constant that means 9999999?

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Table Width (preferredwidth) as 7 nines? (XP)

    Yep, wdUndefined = 9999999.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Table Width (preferredwidth) as 7 nines? (XP)

    Actual width? Well, why didn't you say so. <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

    This works for a plain table that hasn't been monkeyed with:

    Sub Test_CalcTblWidthFromColumns()
    MsgBox "Table is " & PointsToInches(CalcTblWidthFromColumns(Selection.T ables(1))) & " inches wide."
    End Sub

    Function CalcTblWidthFromColumns(tbl As Word.Table) As Single
    Dim col As Word.Column
    For Each col In tbl.Columns
    CalcTblWidthFromColumns = CalcTblWidthFromColumns + col.Width
    Next
    If Not (col Is Nothing) Then Set col = Nothing
    Set tbl = Nothing
    End Function

  5. #5
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Table Width (preferredwidth) as 7 nines? (XP)

    Sadly, most of the tables I view have been "monkeyed with" and querying the column width returns an error message that not all the cells in the column are the same width.

    So it looks like I've got to iterate the whole table, checking the width of each cell on each row. Hmm.. I wonder if the cell width includes bewteen-cell spacing if used (and believe me, my users will have used it, against their own best interests).

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Table Width (preferredwidth) as 7 nines? (XP)

    > I wonder if the cell width includes bewteen-cell spacing if used

    Yes, it does, in my little test.

  7. #7
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Table Width (preferredwidth) as 7 nines? (XP)

    Iterating each cell in each row isn't bad. The problem intrigued me; here's what I came up with:

    <pre>Sub ATableTooWide()

    Dim c As Cell
    Dim cTotalColWidth As Single
    Dim r As Row
    Dim tbl As Table
    Dim MaxWidth As Single
    Dim doc As Document

    Set doc = ActiveDocument
    MaxWidth = doc.PageSetup.PageWidth - _
    doc.PageSetup.RightMargin - _
    doc.PageSetup.LeftMargin

    Dim cWidth As Single
    For Each tbl In ActiveDocument.Tables
    For Each r In tbl.Rows
    For Each c In r.Range.Cells
    cTotalColWidth = cTotalColWidth + c.Width
    Next c
    If cTotalColWidth >= MaxWidth Then
    r.Select
    MsgBox "This row is too wide!", vbExclamation
    End If
    cTotalColWidth = 0
    Next r
    Next tbl

    End Sub
    </pre>


    HTH

  8. #8
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Table Width (preferredwidth) as 7 nines? (XP)

    No, iterating one table isn't so bad... it's iterating hundreds throughout a large document (such as pharmaceutical research clinical trial reports), that have many, many rows and columns that will get bad.

    And that probably won't be the only pass through the cells, as during the same process, I want to check for styles and font usage. This could become intolerably long if I process them separately, and intolerably complex if I process them together.

    Oh, one more thing to check: Each row has a .LeftIndent property. Add the left to your width before calculating (and itcan be negative!), and then figure out whether you're left-justified, centered or right-justified to figure out if you're out of bounds.

    I'll post code when it works.

  9. #9
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Table Width (preferredwidth) as 7 nines? (XP)

    Are you on 2003? This is definitely something you could do with XSLT, extremely quickly.

    (BTW, 1050 tables, 20 cells each, took less than 4 minutes with the code above)

  10. #10
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Table Width (preferredwidth) as 7 nines? (XP)

    Hmm.. that is cool, and on another thread it appears that I could also extract the font list I need from the XSLT, but alas:
    This is for a project to be customized for a number of clients who are using '97, 2000 and XP. None of them are even considering 2003 yet.

  11. #11
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Table Width

    In a document, if I use Table, Properties, the Preferred width is displayed as 7.08 inches. If I go to the VBA editor, and type into the immediate window

    ? selection.tables(1).preferredwidth
    9999999

    is the result I get. Any explanation? I really need to find out whether tables are fitting within the margins.

    Thanks,
    Joel

  12. #12
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Table Width

    Man, table width, or at least figuring out if it's between borders is truly a pain!

    Rows can have their own left indent and alignment (left, right, center).
    However, the actual positioning of a row is dependent on all the other rows' width and left indent!
    For instance, if all rows but one are indented by an inch, and all rows are right justified, the unindented row shows up to the left.
    Exactly the same result appears if the lone row is indented by a negative inch, and the rest are all indent of zero.
    If they are all indented the same distance, and right justified, they're all aligned on the right margin.

    And if the alignments are mixed, I don't know how to guess where things will be.
    I'd love to see their rendering algorithm.

  13. #13
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Table Width

    Your users must have too much freedom. I mean, why are people messing up their tables so much? Don't they value your time? <img src=/S/wink.gif border=0 alt=wink width=15 height=15> Maybe you should extract the data from the table, delete it, and rebuild it in an orderly fashion...

  14. #14
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Table Width

    The thing is, I don't *know* that the tables are that messed up, but I need to create an auditing tool to tell customers when complex documents will have problems with publishing, e.g. outside of margins. If I only check for a fraction of the possible problems, I'm not solving the problem.

  15. #15
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Table Width

    Can you provide an example of a table with a row that my macro above wouldn't flag? I've tried varying combinations of widths and indents, and it still seems to catch any rows wider than the margins.

Page 1 of 2 12 LastLast

Posting Permissions

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