View Single Post
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Conditional Formating

Lisa Mazzanti wrote:
I am creating a form in Word 2003 and wondering if you can use
conditional formating.

I have a number field and when a negative number is entered I want it
to be in red (like you can do in excel)


No, Word doesn't do conditional formatting like Excel.

If embedding a cell from an Excel worksheet in your Word document doesn't
appeal to you, then you'll need a macro like the following, assigned as the
exit macro of the form field in question (or more than one form field):

Sub FormatNegative()
Dim rslt As String
If Selection.Bookmarks.Count Then
With Selection.Bookmarks(1).Range
rslt = .FormFields(1).Result
If ActiveDocument.ProtectionType wdNoProtection Then
ActiveDocument.Unprotect
End If

If IsNumeric(rslt) Then
If Val(rslt) 0 Then
.FormFields(1).Range.Font.Color = wdColorRed
Else
.FormFields(1).Range.Font.Color = wdColorBlack
End If
' Else
' .FormFields(1).Range.Font.Color = wdColorBrightGreen
End If

ActiveDocument.Protect Type:=wdAllowOnlyFormFields,
NoReset:=True
End With
End If
End Sub

See http://www.gmayor.com/installing_macro.htm if needed.

The two lines that start with a single quote are comments. If you want
entries that aren't valid numbers to be highlighted, remove the single
quotes. Of course, you can pick a different color than bright green.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.