Code: Select all
Option Explicit
Dim tCol, i As Integer, tRow As Integer, fFld As String
Sub ColourIt()
Dim Pwd As String, Tint
Pwd = ""
With ActiveDocument
.Unprotect (Pwd)
Select Case .FormFields(fFld).Result
Case "Inspected"
Tint = RGB(171, 229, 123)
Case "Functional"
Tint = RGB(171, 229, 123)
Case "Inspected - Appears Functional"
Tint = RGB(171, 229, 123)
Case "Operational"
Tint = RGB(171, 229, 123)
Case "Not Inspected"
Tint = RGB(190, 190, 190)
Case "Non-Accessible"
Tint = RGB(190, 190, 190)
Case "Limited Inspection"
Tint = RGB(190, 190, 190)
Case "Not Present"
Tint = RGB(120, 220, 255)
Case "Absent / None"
Tint = RGB(120, 220, 255)
Case "Missing"
Tint = RGB(120, 220, 255)
Case "Damaged / Repair Needed"
Tint = RGB(255, 220, 110)
Case "Non-Functional"
Tint = RGB(255, 220, 110)
Case "Recommend Repairs"
Tint = RGB(255, 220, 110)
Case "Monitor Conditions"
Tint = RGB(255, 220, 110)
Case "Unsatisfactory"
Tint = RGB(255, 220, 110)
Case "Unacceptable"
Tint = RGB(255, 220, 110)
Case "Attention Recommended"
Tint = RGB(255, 220, 110)
Case "Attention Required"
Tint = RGB(255, 220, 110)
Case "Defective"
Tint = RGB(255, 220, 110)
Case "Further Inspection Needed"
Tint = RGB(255, 220, 110)
Case "Further Inspection Recommended"
Tint = RGB(255, 220, 110)
Case "Investigate Further"
Tint = RGB(255, 220, 110)
Case "Safety Hazard"
Tint = RGB(250, 100, 95)
Case "Safety Concern"
Tint = RGB(250, 100, 95)
Case "Dangerous"
Tint = RGB(250, 100, 95)
End Select
.Tables(1).Cell(tRow, tCol).Range.Shading.BackgroundPatternColor = Tint
.Protect wdAllowOnlyFormFields, Noreset:=True, Password:=Pwd
End With
End Sub
Sub GetFFRef()
With Selection
If .FormFields.Count = 0 Then End
For i = 1 To ActiveDocument.Tables.Count
If (.Range.Start >= ActiveDocument.Tables(i).Range.Start) And _
(.Range.End <= ActiveDocument.Tables(i).Range.End) Then
Exit For
End If
Next i
With .Cells(1)
fFld = .Range.FormFields(1).Name
tCol = .ColumnIndex
tRow = .RowIndex
End With
End With
End Sub
Code: Select all
.Tables(1).Cell(tRow, tCol).Range.Shading.BackgroundPatternColor = Tint