View Single Post
 
Old 01-06-2015, 06:27 PM
jjfreedman jjfreedman is offline Windows 7 64bit Office 2013
Advanced Beginner
 
Join Date: May 2012
Location: https://jay-freedman.info
Posts: 39
jjfreedman is on a distinguished road
Default

The cause of the error is that oFF.Result is a String value, which has no attributes. That's why the "." notation doesn't work. The thing associated with the formfield that does have a .Font.Color attribute is the oFF.Range member.

If you just try to set the color, you'll get a runtime error saying that it can't be changed because it refers to a protected part of the document. To be successful, you have first unprotect the document, change the color, and then reprotect the document. Try this:

Code:
Sub CountValues()
Dim A_Count As Long
Dim B_Count As Long
Dim C_Count As Long
Dim oFF As FormField
    A_Count = 0
    B_Count = 0
    C_Count = 0
    For Each oFF In ActiveDocument.FormFields
        If oFF.Type = wdFieldFormDropDown Then
            ActiveDocument.Unprotect
            Select Case oFF.Result
                Case "A"
                    A_Count = A_Count + 1
                    oFF.Range.Font.Color = wdColorRed
                Case "B"
                    B_Count = B_Count + 1
                    oFF.Range.Font.Color = wdColorBlue
                Case "C"
                    C_Count = C_Count + 1
                    oFF.Range.Font.Color = wdColorGreen
                Case Else
            End Select
            ActiveDocument.Protect _
                Type:=wdAllowOnlyFormFields, _
                NoReset:=True
        End If
    Next oFF
    MsgBox "A - Selected " & A_Count & vbCr & _
           "B - Selected " & B_Count & vbCr & _
           "C - Selected " & C_Count
lbl_Exit:
    Exit Sub
End Sub
Reply With Quote