我正在尝试编写一个宏来一次更改Word文档中所有表格的所有边框的颜色。
我这样做的尝试仅更改了表格的顶部和底部边框:
Sub ChangeTableBordersColors()
Dim mycolor As WdColor
Dim myTable As Table
mycolor = wdColorRed
For Each myTable In ActiveDocument.Tables
With myTable
.Borders(wdBorderTop).Color = mycolor
.Borders(wdBorderBottom).Color = mycolor
.Borders(wdBorderHorizontal).Color = mycolor
.Borders(wdBorderVertical).Color = mycolor
.Borders(wdBorderLeft).Color = mycolor
.Borders(wdBorderRight).Color = mycolor
End With
Next
End Sub
谁能建议如何解决这个问题?
最佳答案
我没有完整的技巧,但是当单独设置一些边界时,看来您的代码不起作用。
首先重设LineStyle和LineWidth,然后重设颜色对我有用。
您可以将其缩短为:
With myTable
.Borders.InsideLineStyle = wdLineStyleSingle
.Borders.InsideLineWidth = wdLineWidth025pt
.Borders.InsideColor = mycolor
.Borders.OutsideLineStyle = wdLineStyleSingle
.Borders.OutsideLineWidth = wdLineWidth025pt
.Borders.OutsideColor = mycolor
End With