Reputation: 1296
I have a macro that I'm using to remove all of the color in all of the tables in certain Word Documents. The colors being removed are there initially to indicate where someone should type.
Trust me, I'd rather use form fields or ActiveX text boxes, but this is not a situation where they will work as Word is being opened through a 3rd party application that invalidates these with a mail merge. Anyway, I want to skip over the first table. I have the code below set up to do it, then change the first cell of the first table back to a particular color.
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
This works fine for removing the color, but the color of that first cell of the first table isn't the same in all of them. I just want to skip the first table during the for each loop. I've tried an if statement (If tbl = ActiveDocument.Tables(1) Then...) but evidently this is not an allowed comparison as it doesn't recognize the Then statement. I've also tried doing this with a range, but couldn't quite get it right. Any thoughts would be appreciated.
Upvotes: 2
Views: 1258
Reputation: 21
if activedocument.Tables.Count >1 then
for x = 2 to activedocument.Tables.Count
activedocument.Tables(x).Shading.BackgroundPatternColor = wdColorWhite
next x
end if
Upvotes: 0
Reputation: 708
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
Upvotes: 2