View Single Post
 
Old 01-06-2015, 10:55 PM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The macro is intended to be run separately. If you want a macro to run on exit from the form field(s) then run the following on exit from and on entry to each form field

Code:
Option Explicit
Public rngFF As Word.Range
Public fldFF As Word.FormField

Public Sub DropDownColour()
Dim bProtected As Boolean
    With GetCurrentFF
        If .Type = wdFieldFormDropDown Then
            'Unprotect the file
            If ActiveDocument.ProtectionType <> wdNoProtection Then
                bProtected = True
                ActiveDocument.Unprotect Password:=""
            End If

            Select Case .Result
                Case "A": .Range.Font.ColorIndex = wdRed
                Case "B": .Range.Font.ColorIndex = wdYellow
                Case "C": .Range.Font.ColorIndex = wdGreen
                Case Else
            End Select
            'Reprotect the document.
            If bProtected = True Then
                ActiveDocument.Protect _
                        Type:=wdAllowOnlyFormFields, _
                        NoReset:=True, _
                        Password:=""
            End If
        End If
    End With
lbl_Exit:
    Exit Sub
End Sub

Public Function GetCurrentFF() As Word.FormField
    Set rngFF = Selection.Range
    rngFF.Expand wdParagraph
    For Each fldFF In rngFF.FormFields
        Set GetCurrentFF = fldFF
        Exit For
    Next fldFF
lbl_Exit:
    Exit Function
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote