Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Sep 2004
    Location
    Portsmouth, Hampshire, England
    Posts
    200
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Missing property? (XP 2002 SP2)

    Hi y'all
    I have two small macros set up to format tables the way I like them. One of them (Tableformat) operates on the current table and the other one (Tablesformat) on all the tables in the document.

    So far so good.

    However, I though, why have two almost identical macros, why not have a private sub that is called by each of them and is passed a table object.

    Well, first of all I tried:
    <pre>Sub Tablesformat()
    Dim t As Table
    For Each t In ActiveDocument.Tables
    doTableformat (t)
    Next
    Exit Sub
    </pre>



    Calling:
    Private Sub doTableformat(t As Table)

    But that gave me a type mismatch error? I'd love it if someone could tell me why?

    Then I tried swapping and using a Variant.
    All seemed to work well with this, untill I reached the line:
    With .Borders(wdBorderVertical)

    When I got the error "The requested member of the collection does not exist"?

    So why does this particular attribute not exist when I call the sub with a table object, when it does exist if I just loop in the code?

    More to the point, how do I achieve the end goal of having a sub that I can call with a table object?

    Here is the doTableformat Sub:
    <pre>Private Sub doTableformat(t As Variant)

    With t
    With .Rows.First
    .HeadingFormat = True
    With .Shading
    .Texture = wdTextureNone
    .ForegroundPatternColor = wdColorAutomatic
    .BackgroundPatternColor = wdColorGray20
    End With
    End With
    .Rows.AllowBreakAcrossPages = False
    .Rows.First.Range.ParagraphFormat.KeepWithNext = True
    With .Borders(wdBorderLeft)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorGray50
    End With
    With .Borders(wdBorderRight)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorGray50
    End With
    With .Borders(wdBorderTop)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorGray50
    End With
    With .Borders(wdBorderBottom)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorGray50
    End With
    With .Borders(wdBorderHorizontal)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorGray50
    End With
    With .Borders(wdBorderVertical)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorGray50
    End With
    End With
    End Sub
    </pre>


    TIA
    Regards
    Paul

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

    Re: Missing property? (XP 2002 SP2)

    You can use
    <code>
    Private Sub doTableformat(t As Table)
    </code>
    but you must call it as
    <code>
    doTableformat t
    </code>
    i.e. don't use <code>(t)</code> since it changes t to a ByVal argument.

    If a table has only one row, .Borders(wdBorderHorizontal) is not available, and if it has only one column, .Borders(wdBorderVertical) is not available. You can get around this to test for the number of rows/columns:
    <pre> If .Rows.Count > 1 Then
    With .Borders(wdBorderHorizontal)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorGray50
    End With
    End If
    If .Columns.Count > 1 Then
    With .Borders(wdBorderVertical)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorGray50
    End With
    End If
    </pre>

    This skips the code if it is not applicable.

  3. #3
    3 Star Lounger
    Join Date
    Sep 2004
    Location
    Portsmouth, Hampshire, England
    Posts
    200
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Missing property? (XP 2002 SP2)

    Thanks Hans,
    I still wonder why it was only that one property that was missing when it was failing.

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

    Re: Missing property? (XP 2002 SP2)

    The top, left, right and bottom borders are always available, whatever the number of rows and columns is. The horizontal borders between cells are only available if there is more than one row, and similar for the vertical borders between cells.

  5. #5
    3 Star Lounger
    Join Date
    Sep 2004
    Location
    Portsmouth, Hampshire, England
    Posts
    200
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Missing property? (XP 2002 SP2)

    Yeah I got that,
    but this is the same table. All the other properties seemed to get passed OK, but that one did not.

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

    Re: Missing property? (XP 2002 SP2)

    Sorry, you've lost me.

  7. #7
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Missing property? (XP 2002 SP2)

    I don't have a reason for the Vertical Border to fail but I would be inclined to modify the code to use a table style instead.

    In the past I have found the code to colour the table borders to be very slow. A far faster method of applying the shading and borders is to apply a table style.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  8. #8
    3 Star Lounger
    Join Date
    Sep 2004
    Location
    Portsmouth, Hampshire, England
    Posts
    200
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Missing property? (XP 2002 SP2)

    I've never really played around with table styles. I'll take a look, thanks.

    However, very slow is relative. The macro does 10 tables in about a second which is quick enough for me.

Posting Permissions

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