知方号

知方号

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

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

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

Sub Hong2() Dim tb As Table With ActiveDocument For Each tb In .Tables Next End WithEnd 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 WithEnd 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 = TrueEnd Sub 遍历所有的表,依次选中表头: Sub SelectTableHeader()Dim tb as TableWith ActiveDocumentFor Each tb In .Tables.Range(tb.Cell(1,1).Range.Start,tb.Cell(1,tb.Columns.Count).Range.End).SelectNextEnd WithEnd Sub遍历所有的表头,将表头背景设置为浅灰色: Sub Hong3()Dim tb as TableWith ActiveDocumentFor Each tb In .Tables.Range(tb.Cell(1,1).Range.Start,tb.Cell(1,tb.Columns.Count).Range.End).SelectSelection.Shading.BackgroundPatternColor = wdColorGray20NextEnd WithEnd 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 WithEnd 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 WithEnd Sub

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lizi9903@foxmail.com举报,一经查实,本站将立刻删除。