2013-01-08 48 views
2

我有我使用删除所有在特定Word文档表格的所有颜色的宏。被删除的颜色最初表示某人应该输入的位置。改变颜色,而是在Word中一个表VBA

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

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 

这工作得很好去除颜色,但在第一个表格是第一个单元格的颜色是不是在所有的人都一样。我只想在每个循环中跳过第一个表格。我试过一个if语句(如果TBL = ActiveDocument.Tables(1),然后...),但显然这不是允许的比较,因为它不承认当时的声明。我也试着用范围来做这个,但是不太对。任何想法将不胜感激。

回答

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 
+0

哇哦......说说咄!完美的作品。谢谢你的帮助。 –

0
if activedocument.Tables.Count >1 then 

     for x = 2 to activedocument.Tables.Count 

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

     next x 

    end if