I have a macro to determine table cell shading color RGB 200, 200, 200. Most of my documents based with this table cell shading RGB color.
Code: Select all
Sub FindTableCellShading()
Dim TBL As Table
Dim C As Cell
Dim i As Long
Dim n As Long
Dim tblNum As Long
Dim StandardShade As Boolean
Dim tblList As String
Application.ScreenUpdating = False
Options.Pagination = False
If ActiveDocument.Words.Count = 1 Then
MsgBox "Seems like this is empty document! Please check and try again.", vbExclamation
Exit Sub
Else
If ActiveDocument.Tables.Count = 0 Then
MsgBox "Seems like this document contains no tables", vbExclamation
Exit Sub
Else
On Error GoTo Error
With ActiveDocument
tblNum = 0
For Each TBL In .Tables
tblNum = tblNum + 1
n = TBL.Rows.Count
For i = n To 1 Step -1
StandardShade = True
For Each C In TBL.Rows(i).Cells
' If cell shading <> "Standard Shading" or "No shading", alert!
If C.Shading.BackgroundPatternColor <> 13158600 Then ' Standard Shading Color (RGB 200, 200, 200)
If C.Shading.BackgroundPatternColor <> 16576719 Then ' Blank Shading (No Color)
If C.Shading.BackgroundPatternColor <> wdColorWhite Then ' Blank Shading (No Color)
If C.Shading.BackgroundPatternColor <> -603914241 Then ' White, Background 1
StandardShade = False
Exit For
End If
End If
End If
End If
Next C
If StandardShade = False Then
tblList = tblList & tblNum & ","
Exit For
End If
Next i
Next TBL
End With
End If
End If
Set C = Nothing: Set TBL = Nothing
Application.ScreenUpdating = True
Options.Pagination = True
If Len(tblList) > 0 Then
tblList = Left(tblList, Len(tblList) - 1)
MsgBox ("Non Standard shading exists in this document in tables:" & vbTab & vbTab & tblList), vbExclamation
Else
MsgBox ("All shading matches standard color (RGB 200, 200, 200) or is blank"), vbInformation
End If
Exit Sub
Error:
MsgBox ("Seems like this document table(s) contains vertically merged cells! " & tblList), vbExclamation
End Sub
I think it would be very helpful me if can add a input RGB color user forum before run this macro. But the problem is I have no idea how to convert RGB to VBA color code. Any options to do this?
Thank you!
Have a great weekend.