2

我有一个宏,用于删除某些 Word 文档中所有表格中的所有颜色。被删除的颜色最初是为了指示某人应该在哪里输入。

相信我,我宁愿使用表单域或 ActiveX 文本框,但这不是它们可以工作的情况,因为 Word 是通过第 3 方应用程序打开的,该应用程序通过邮件合并使这些应用程序无效。无论如何,我想跳过第一张桌子。我设置了下面的代码来执行此操作,然后将第一个表格的第一个单元格更改回特定颜色。

Sub decolordocument()
'
' decolordocument Macro
'
'
Dim tbl As Table

For Each tbl In ActiveDocument.Tables
tbl.Shading.BackgroundPatternColor = wdColorWhite
Next
ActiveDocument.Tables(1).Cell(1, 1).Shading.BackgroundPatternColor = wdColorLightTurquoise

End Sub

这可以很好地去除颜色,但第一个表格的第一个单元格的颜色在所有表格中都不相同。我只想在 for each 循环期间跳过第一个表。我尝试了一个 if 语句(If tbl = ActiveDocument.Tables(1) Then...),但显然这不是允许的比较,因为它无法识别 Then 语句。我也试过用一个范围来做这个,但不能完全正确。任何想法将不胜感激。

4

2 回答 2

2
Sub decolordocument()
'
' decolordocument Macro
'
'
Dim first as Boolean
Dim tbl As Table

first = true

For Each tbl In ActiveDocument.Tables
If first Then
first = false
Else
tbl.Shading.BackgroundPatternColor = wdColorWhite
End If
Next
'ActiveDocument.Tables(1).Cell(1, 1).Shading.BackgroundPatternColor = wdColorLightTurquoise

End Sub
于 2013-01-08T17:11:13.243 回答
0
    if activedocument.Tables.Count >1   then

      for x = 2 to activedocument.Tables.Count

     activedocument.Tables(x).Shading.BackgroundPatternColor = wdColorWhite

      next x

    end if
于 2017-08-14T06:28:05.477 回答