Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 01-06-2015, 06:27 PM
jjfreedman jjfreedman is offline Macro to check dropdown value and increment a counter Windows 7 64bit Macro to check dropdown value and increment a counter 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
 

Tags
bookmarks, word 2003, word vba macro



Similar Threads
Thread Thread Starter Forum Replies Last Post
Dropdown list, Macro shield5 Excel Programming 7 10-27-2013 01:51 AM
Macro to check dropdown value and increment a counter macro not working (on click increment) gsrikanth Excel Programming 1 07-12-2012 07:40 AM
Check box macro help needed Aflac Word 4 03-24-2012 07:11 PM
Macro to populate a text form field based on dropdown selection koloa Word 0 10-20-2011 11:52 AM
Macro to check dropdown value and increment a counter Check Box Macro Johnny thunder Word VBA 12 04-07-2011 04:47 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:06 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft