none
WORD TABLE ROW BORDERS RRS feed

  • Question

  • I have a Word macro that runs through a table and changes the shading on alternate rows. (see below)

    The problem is that it also changes the rows border properties. Some of the rows have an under-border (to server as an full width underline) and I don't want the macro to change the border properties for any of the rows. I have tried using .ForegroundPatternColor but can't see the difference.

    Any ideas would be most welcome! Thanks in advance!

    Sub ShadeManual()
    Dim i As Integer
    Dim rows1 As Rows
    Dim returnValue As Borders

    With Selection
        With .Tables(1)
            For i = 1 To .Rows.Count
            
                With .Rows(i).Shading
                   If i Mod 2 = 0 Then
                      .BackgroundPatternColor = wdColorAqua
                   End If
                End With
            Next
        End With
    End With
    End Sub

    Friday, March 9, 2012 9:41 PM

Answers

  • Hi Rothy,

    Given that something is happening between the table's construction in Excel and its replication in Word, the simplest solution might be to apply the shading in Excel before the table is copied to Word (assuming you can access the Excel object at that stage). For my part, I've not yet been able to discover a cell bordering/underlining arrangement in Excel that does not faithfully replicate when the table is copied to Word.

    The alternative, if you can't apply the shading in Excel, is to re-apply the cell borders in Word. This could be done by reference to the row number or by its content. I note, for example, that all rows beginning with 'Net' or 'Total' have top & bottom borders, as do the 'Operating income' & '(Millions ...' rows and that the 'Earnings ...' row has a bottom border.

    Something else that is curious about your shaded table, that may give a clue, is that the borders are not removed consistently. After shading, it seems to remain below the '(Millions ...' and 'Total operating expenses' rows, but not below other white rows.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by rothy909 Saturday, March 10, 2012 10:24 PM
    Saturday, March 10, 2012 9:41 PM

All replies

  • Hi Rothy,

    I don't see that behaviour. Is the printout affected? If not, it may just be a display issue. Aside from that, your code could do with a bit more error-checking, etc. As it is, no check it made whether the selection is actually in a table and, if a row is added/deleted, re-running the code will colour every row below that. Try:

    Sub ShadeManual()
    Dim i As Long
    With Selection
      If .Information(wdWithInTable) = False Then Exit Sub
      With .Tables(1)
        For i = 1 To .Rows.Count
          With .Rows(i).Shading
            If i Mod 2 = 0 Then
              .BackgroundPatternColor = wdColorAqua
            Else
              .BackgroundPatternColor = wdColorAutomatic
            End If
          End With
        Next
      End With
    End With
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, March 9, 2012 10:06 PM
  • Paul,

    Thanks for the response. The lines are definitely gone on my side. I attached some screen shots below. Look at the lines under the year headings as an example. I used your script as is.

    Saturday, March 10, 2012 2:26 AM
  • Hi Rothy,

    I'm still not seeing that behaviour. Again: Is the printout affected? If not, it may just be a display issue. In that case, you should check the display card maker's website for an updated driver. If the printout is affected, that raises the question of exactly how you're doing the unerlining. In my testing, I'm simply using bottom cell borders, with and without gridlines & formatting marks displayed.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Saturday, March 10, 2012 2:55 AM
  • Paul, I appreciate your help!

    My print out is affected.

    My Word document is generated by Cognos Financial Statement Reporter (FSR). The FSR application is used to generate 10-Q & 10-K for public companies. The FSR database is comprised of multiple Excel Objects & Word Objects which when 'generated' produce 1 Word object. The object/page causing concern is derived from an Excel object. When formatting this object/page in Excel I use the Border tool to make top and/or bottom lines, however, when it generates the Word object I notice that if I click on the cell in the table the Border icon does not light up. Although if I double click on the cell and then right click to look at 'Border and Shading' properties it does show the top and/or bottom borders there. Not sure why that is but I guess my problem is that FSR is not generating the Word document formatting exactly like the original Excel.

    Saturday, March 10, 2012 7:56 PM
  • Hi Rothy,

    Given that something is happening between the table's construction in Excel and its replication in Word, the simplest solution might be to apply the shading in Excel before the table is copied to Word (assuming you can access the Excel object at that stage). For my part, I've not yet been able to discover a cell bordering/underlining arrangement in Excel that does not faithfully replicate when the table is copied to Word.

    The alternative, if you can't apply the shading in Excel, is to re-apply the cell borders in Word. This could be done by reference to the row number or by its content. I note, for example, that all rows beginning with 'Net' or 'Total' have top & bottom borders, as do the 'Operating income' & '(Millions ...' rows and that the 'Earnings ...' row has a bottom border.

    Something else that is curious about your shaded table, that may give a clue, is that the borders are not removed consistently. After shading, it seems to remain below the '(Millions ...' and 'Total operating expenses' rows, but not below other white rows.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by rothy909 Saturday, March 10, 2012 10:24 PM
    Saturday, March 10, 2012 9:41 PM