PDA

View Full Version : How can I add internal borders to a Word table after encountering an error?



soulpow3r
11-14-2011, 11:56 PM
For a Word 97-02 doc table, I've modified the following macro from http://www.thedoctools.com/downloads/basTableBorder.shtml
for my purposes so that it now looks like this:


Sub ApplyUniformBordersToAllTables()
Dim oTable As Table
Dim oBorderStyle As WdLineStyle
Dim oBorderWidth As WdLineWidth
Dim oBorderColor As WdColor
Dim oarray As Variant
Dim n As Long
Dim i As Long
'=========================
'Change the values below to the desired style, width and color
oBorderStyle = wdLineStyleSingle
oBorderWidth = wdLineWidth050pt
oBorderColor = wdColorAutomatic
'=========================
'Define array with the borders to be changed
oarray = Array(wdBorderTop, _
wdBorderLeft, _
wdBorderBottom, _
wdBorderRight, _
wdBorderHorizontal, _
wdBorderVertical)
For Each oTable In ActiveDocument.Tables
'Count tables - used in message
n = n + 1
With oTable
For i = LBound(oarray) To UBound(oarray)
'Skip if only one row and wdBorderHorizontal
If .Rows.Count = 1 And oarray(i) = wdBorderHorizontal Then GoTo Skip
'Skip if only one column and wdBorderVertical
If .Columns.Count = 1 And oarray(i) = wdBorderVertical Then GoTo Skip
With .Borders(oarray(i))
.LineStyle = oBorderStyle
.LineWidth = oBorderWidth
.Color = oBorderColor
End With
Next i
End With
Skip:
Next oTable
End Sub

The macro was modified to prevent errors when it encounters tables with only one row or one column, however, it still doesn't add the internal borders after encountering the problem.

Can anyone offer any suggestions?

Tinbendr
11-18-2011, 08:16 AM
On Error Resume Next
For Each oTable In ActiveDocument.Tables
'Count tables - used in message
n = n + 1
With oTable
For i = LBound(oarray) To UBound(oarray)
'Skip if only one row and wdBorderHorizontal
'If .Rows.Count = 1 And oarray(i) = wdBorderHorizontal Then GoTo Skip
'Skip if only one column and wdBorderVertical
'If .Columns.Count = 1 And oarray(i) = wdBorderVertical Then GoTo Skip