vba - 如何使用vba宏从ms word文档中隐藏背景颜色为灰色的表格单元格
问题描述
我的 word doc 中有很多不同类型的表格。从那个灰色单元格不可用,所以我必须隐藏它(不想删除它)。表格的行数和列数总是不一样的。所以我不知道如何使用vba宏从ms word文档中隐藏背景颜色为灰色的表格单元格????
Sub ClearTableBGColor()
Dim t As Table
For Each t In ActiveDocument.Tables
If t.Shading.BackgroundPatternColor = Grey Then
t.Shading.BackgroundPatternColor.Hidden = True
End If
Next
End Sub
解决方案
关于您将获得的最好的表格,如您的屏幕截图显示,与以下宏的作用类似。
Sub Demo()
Application.ScreenUpdating = False
Dim Tbl As Table, c As Long
With ActiveDocument
For Each Tbl In .Tables
With Tbl.Range
For c = 1 To .Cells.Count
With .Cells(c).Range
If .Shading.BackgroundPatternColorIndex = wdGray25 Then
With .ParagraphFormat
.SpaceBefore = 0
.SpaceAfter = 0
.LineSpacingRule = wdLineSpaceExactly
.LineSpacing = 0.7
End With
.Font.Hidden = True
End If
End With
Next
End With
Next
End With
Application.ScreenUpdating = True
End Sub
请注意,您不能以这种方式完全隐藏一行。
推荐阅读
- python - 获取属性错误='NoneType'对象没有属性'content'
- php - 从 IP 地址数组中将 PHP 中的数字加一
- twilio - 是否有 Twilio Studio 对象的存储库?
- javascript - 如何将 JSON 数据从服务器传递到客户端并在 Javascript 中使用数据?
- python - 如何阻止 Networkx 将边缘中的头尾节点(u,v)的顺序更改为(v,u)?
- c# - Python 阅读电子邮件
- solr - 将 ContextField 添加到 SOLR 建议器
- python - 用于具有许多任务的工作流的 apache 气流的更快替代方案
- mysql - 使用 REGEX 从 mySQL 中的表列中选择字符串模式
- docker - 在其他分区上安装 docker 时出错