K
kill_beast
I'm trying to create a more modular exit and entry macros for a group of form
fields.
The macros are going to be bascially the same fro all of them, so I want to
avoid having to create a specific macro for each field.
What I have so far:
Sub Exit_Entry()
'unprotect document
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""
End If
If Selection.FormFields.Count > 0 Then
With Selection.FormFields(1)
If .Type = wdFieldFormDropDown Then
If .DropDown.Default <> .DropDown.Value Then
.Range.Font.Color = wdColorRed
.Range.Font.Bold = True
Else
.Range.Font.Color = wdColorAutomatic
.Range.Font.Bold = False
End If
ElseIf .Type = wdFieldFormTextInput Then
If .TextInput.Default <> .Result Then
.Range.Font.Color = wdColorRed
.Range.Font.Bold = True
Else
.Range.Font.Color = wdColorAutomatic
.Range.Font.Bold = False
End If
End If
End With
End If
'protect document
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:=""
End Sub
It's supposed to bold and color red non default values in form fields upon
entry or exit. This works perfectly for drop downs. Using a message a box
to show me the Selection.FormFields.Count number, it's because when I enter
or exit a drop down, the Selection property actually has a formfield
selected, and the message box would display "1". With the text fields,
however, it displays 0, and so the macro fails and the text formatting never
occurs.
Is there a better or different way to do this that will make it work for
both Dropdowns and Text Inputs?
fields.
The macros are going to be bascially the same fro all of them, so I want to
avoid having to create a specific macro for each field.
What I have so far:
Sub Exit_Entry()
'unprotect document
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""
End If
If Selection.FormFields.Count > 0 Then
With Selection.FormFields(1)
If .Type = wdFieldFormDropDown Then
If .DropDown.Default <> .DropDown.Value Then
.Range.Font.Color = wdColorRed
.Range.Font.Bold = True
Else
.Range.Font.Color = wdColorAutomatic
.Range.Font.Bold = False
End If
ElseIf .Type = wdFieldFormTextInput Then
If .TextInput.Default <> .Result Then
.Range.Font.Color = wdColorRed
.Range.Font.Bold = True
Else
.Range.Font.Color = wdColorAutomatic
.Range.Font.Bold = False
End If
End If
End With
End If
'protect document
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:=""
End Sub
It's supposed to bold and color red non default values in form fields upon
entry or exit. This works perfectly for drop downs. Using a message a box
to show me the Selection.FormFields.Count number, it's because when I enter
or exit a drop down, the Selection property actually has a formfield
selected, and the message box would display "1". With the text fields,
however, it displays 0, and so the macro fails and the text formatting never
occurs.
Is there a better or different way to do this that will make it work for
both Dropdowns and Text Inputs?