Conditional Formating

  • Thread starter Thread starter Lisa Mazzanti
  • Start date Start date
L

Lisa Mazzanti

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)
 
Lisa said:
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
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top