World文档中所有的表格边框突然没有了,怎么办?

这个问题已经是第二次遇到了,感觉Office很不靠谱,辛辛苦苦写的文档,之前都好好的,然后某一天打开,发现里面所有的表格都没有了边框,好奇怪...   最要命的是这个文档你需要马上提交,这个时候宏就派上用场了。
首先来看一个遍历所有表格的宏:

Sub Hong2()
    Dim tb As Table
    With ActiveDocument
        For Each tb In .Tables
            
        Next
    End With
End Sub
很简单吧,下面就不绕圈子了,直接来结果吧:
Sub Hong2()
    Dim tb As Table
    With ActiveDocument
        For Each tb In .Tables
            With tb
                With .Borders(wdBorderLeft)
                    .LineStyle = wdLineStyleSingle
                    .LineWidth = wdLineWidth050pt
                    .Color = wdColorAutomatic
                End With
                With .Borders(wdBorderRight)
                    .LineStyle = wdLineStyleSingle
                    .LineWidth = wdLineWidth050pt
                    .Color = wdColorAutomatic
                End With
                With .Borders(wdBorderTop)
                    .LineStyle = wdLineStyleSingle
                    .LineWidth = wdLineWidth050pt
                    .Color = wdColorAutomatic
                End With
                With .Borders(wdBorderBottom)
                    .LineStyle = wdLineStyleSingle
                    .LineWidth = wdLineWidth050pt
                    .Color = wdColorAutomatic
                End With
                With .Borders(wdBorderHorizontal)
                    .LineStyle = wdLineStyleSingle
                    .LineWidth = wdLineWidth050pt
                    .Color = wdColorAutomatic
                End With
                With .Borders(wdBorderVertical)
                    .LineStyle = wdLineStyleSingle
                    .LineWidth = wdLineWidth050pt
                    .Color = wdColorAutomatic
                End With
                .Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
                .Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
                .Borders.Shadow = False
            End With
        Next
    End With
    With Options
        .DefaultBorderLineStyle = wdLineStyleSingle
        .DefaultBorderLineWidth = wdLineWidth050pt
        .DefaultBorderColor = wdColorAutomatic
    End With
End Sub
哈哈,完成了....

把这段代码粘贴到宏编辑器里,然后运行,ok,问题解决了...

根据这个,还可以衍生出其它的一些宏,下面是我写的,以备不时只需:
自动选中所有表格:
Sub SelectAllTables()
    Dim mytable As Table
    Application.ScreenUpdating = False
    
    For Each mytable In ActiveDocument.Tables
        mytable.Range.Editors.Add wdEditorEveryone
    Next
    ActiveDocument.SelectAllEditableRanges (wdEditorEveryone)
    ActiveDocument.DeleteAllEditableRanges (wdEditorEveryone)
    Application.ScreenUpdating = True
End Sub 
遍历所有的表,依次选中表头:
Sub SelectTableHeader()
Dim tb as Table
With ActiveDocument
For Each tb In .Tables
.Range(tb.Cell(1,1).Range.Start,tb.Cell(1,tb.Columns.Count).Range.End).Select
Next
End With
End Sub
遍历所有的表头,将表头背景设置为浅灰色:
Sub Hong3()
Dim tb as Table
With ActiveDocument
For Each tb In .Tables
.Range(tb.Cell(1,1).Range.Start,tb.Cell(1,tb.Columns.Count).Range.End).Select
Selection.Shading.BackgroundPatternColor = wdColorGray20
Next
End With
End Sub
下面的代码实现同样的功能:
Sub Hong4()
    Dim tb As Table
    With ActiveDocument
        For Each tb In .Tables
            .Range(tb.Cell(1, 1).Range.Start, tb.Cell(1, tb.Columns.Count).Range.End).Shading.BackgroundPatternColor = wdColorGray20
        Next
    End With
End Sub
下面的代码设置表头的字体和颜色:
Sub Hong5()
    Dim tb As Table
    With ActiveDocument
        For Each tb In .Tables
            .Range(tb.Cell(1, 1).Range.Start, tb.Cell(1, tb.Columns.Count).Range.End).Font.Color = wdColorRed
            .Range(tb.Cell(1, 1).Range.Start, tb.Cell(1, tb.Columns.Count).Range.End).Font.Size = 9
        Next
    End With
End Sub



  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

深蓝静音

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值