I have documents that use paragraph style borders in tables instead of cell borders, and need a macro which will change them in each case to cell borders. After some online research I've come up with the following code, which works to some extent, but there are two problems:
- If the text has a character style enabled, the macro skips that text altogether (I need the character style to stay).
- The macro left aligns everything that it does change, but I need it to ignore alignment and keep it as it was.
Here is the code I am using:
Sub AutoFormatTables2024()
'Removes paragraph rules and replaces them with cell borders
Dim oCell As Cell
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
For Each oCell In oTable.Range.Cells
Select Case True
Case oCell.Range.Style = ActiveDocument.Styles("_table figshead thin")
Options.DefaultBorderLineWidth = wdLineWidth050pt
oCell.Range.Style = ActiveDocument.Styles("_table figshead")
With oCell.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
Case oCell.Range.Style = ActiveDocument.Styles("_table figs thin")
Options.DefaultBorderLineWidth = wdLineWidth050pt
oCell.Range.Style = ActiveDocument.Styles("_table figs")
With oCell.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
Case oCell.Range.Style = ActiveDocument.Styles("_table figs thick")
Options.DefaultBorderLineWidth = wdLineWidth150pt
oCell.Range.Style = ActiveDocument.Styles("_table figs")
With oCell.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
End Select
Next oCell
Next oTable
MsgBox "All done!"
End Sub
Hope someone can help!