Tuesday, 28 October 2014

Microsoft Word Table Color Macro

The following macros can be used to change the color of the first columns in a table, and also to control the border color.

Sub ApplyBordersToAllTables()

Dim oTable As Table
Dim oBorderStyle As WdLineStyle
Dim oBorderWidth As WdLineWidth
Dim oBorderColor As WdColor
Dim n As Long 'used to count tables for message
Dim i As Long 'used with array
Dim oArray As Variant

'Change the values below to apply other borders
oBorderStyle = wdLineStyleSingle
oBorderWidth = wdLineWidth050pt
oBorderColor = wdColorBlue

'Define array with the borders to be changed
'Diagonal borders not included here
oArray = Array(wdBorderTop, _
wdBorderLeft, _
wdBorderBottom, _
wdBorderRight, _
wdBorderHorizontal, _
wdBorderVertical)

For Each oTable In ActiveDocument.Tables
n = n + 1
With oTable
For i = LBound(oArray) To UBound(oArray)
With .Borders(oArray(i))
.LineStyle = oBorderStyle
.LineWidth = wdLineWidth050pt
.Color = wdColorBlack
End With
Next i
End With
Next oTable

MsgBox "Finished applying borders to " & n & " tables."
End Sub
   
   
Sub decolordocument()
'
' decolordocument Macro
'
'
Dim first As Boolean
Dim tbl As Table
n = 0
For Each tbl In ActiveDocument.Tables
tbl.Shading.BackgroundPatternColor = wdColorWhite
n = n + 1
y = 1
    For Each Col In tbl.Columns
                ActiveDocument.Tables(n).Cell(1, y).Shading.BackgroundPatternColor = wdColorLightBlue
                y = y + 1
    Next
Next

No comments:

Post a Comment