#1   Report Post  
Patricia
 
Posts: n/a
Default Conditional Formatting

I am creating a word template and want to know if I can apply a conditional
formatting (like Excel) to the form field based on the value. I cannot find
anything in the help.

Thanks
  #2   Report Post  
Greg
 
Posts: n/a
Default

Patricia,

Here is a few macro options that you set to run on exit from the
formfield that should give you a start:

Sub Format()
Dim oDoc As Document
Set oDoc = ActiveDocument
If oDoc.FormFields("Text1").Result "50" Then
oDoc.FormFields("Text1").Range.Font.Color = wdColorBrightGreen
Else
oDoc.FormFields("Text1").Range.Font.Color = wdColorAutomatic
End If
End Sub
Sub ColorField()
Dim content As String
With ActiveDocument.FormFields("Text2")
content = .Result
Select Case LCase(content)
Case "yes":
.Range.Font.Color = wdColorGreen
Case "no":
.Range.Font.Color = wdColorRed
Case Else:
.Range.Font.Color = wdColorAutomatic
End Select
End With
End Sub

  #3   Report Post  
Posted to microsoft.public.word.docmanagement
inay
 
Posts: n/a
Default Conditional Formatting

Hi Greg

When i test the below script by inserting it into a word document i get an
error message 'requested collection not available'. Do you know what might
be causing this?

Thanks,
Yani

"Greg" wrote:

Patricia,

Here is a few macro options that you set to run on exit from the
formfield that should give you a start:

Sub Format()
Dim oDoc As Document
Set oDoc = ActiveDocument
If oDoc.FormFields("Text1").Result "50" Then
oDoc.FormFields("Text1").Range.Font.Color = wdColorBrightGreen
Else
oDoc.FormFields("Text1").Range.Font.Color = wdColorAutomatic
End If
End Sub
Sub ColorField()
Dim content As String
With ActiveDocument.FormFields("Text2")
content = .Result
Select Case LCase(content)
Case "yes":
.Range.Font.Color = wdColorGreen
Case "no":
.Range.Font.Color = wdColorRed
Case Else:
.Range.Font.Color = wdColorAutomatic
End Select
End With
End Sub


  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor
 
Posts: n/a
Default Conditional Formatting

You don't have a form field called Text1 or in the case of the second macro
Text2. Change the names to match your field names.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


inay wrote:
Hi Greg

When i test the below script by inserting it into a word document i
get an error message 'requested collection not available'. Do you
know what might be causing this?

Thanks,
Yani

"Greg" wrote:

Patricia,

Here is a few macro options that you set to run on exit from the
formfield that should give you a start:

Sub Format()
Dim oDoc As Document
Set oDoc = ActiveDocument
If oDoc.FormFields("Text1").Result "50" Then
oDoc.FormFields("Text1").Range.Font.Color = wdColorBrightGreen
Else
oDoc.FormFields("Text1").Range.Font.Color = wdColorAutomatic
End If
End Sub
Sub ColorField()
Dim content As String
With ActiveDocument.FormFields("Text2")
content = .Result
Select Case LCase(content)
Case "yes":
.Range.Font.Color = wdColorGreen
Case "no":
.Range.Font.Color = wdColorRed
Case Else:
.Range.Font.Color = wdColorAutomatic
End Select
End With
End Sub



  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Stan
 
Posts: n/a
Default Conditional Formatting

I tried this excellent macro, but, I guess it won't work on mail merge
fields. I'm not a programmer, so if you have any suggestions, I'd be much
obliged. Thanks!

"Graham Mayor" wrote:

You don't have a form field called Text1 or in the case of the second macro
Text2. Change the names to match your field names.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


inay wrote:
Hi Greg

When i test the below script by inserting it into a word document i
get an error message 'requested collection not available'. Do you
know what might be causing this?

Thanks,
Yani

"Greg" wrote:

Patricia,

Here is a few macro options that you set to run on exit from the
formfield that should give you a start:

Sub Format()
Dim oDoc As Document
Set oDoc = ActiveDocument
If oDoc.FormFields("Text1").Result "50" Then
oDoc.FormFields("Text1").Range.Font.Color = wdColorBrightGreen
Else
oDoc.FormFields("Text1").Range.Font.Color = wdColorAutomatic
End If
End Sub
Sub ColorField()
Dim content As String
With ActiveDocument.FormFields("Text2")
content = .Result
Select Case LCase(content)
Case "yes":
.Range.Font.Color = wdColorGreen
Case "no":
.Range.Font.Color = wdColorRed
Case Else:
.Range.Font.Color = wdColorAutomatic
End Select
End With
End Sub






  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor
 
Posts: n/a
Default Conditional Formatting

The macro was intended to be used with form fields. What *exactly* are you
trying to do?

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


Stan wrote:
I tried this excellent macro, but, I guess it won't work on mail merge
fields. I'm not a programmer, so if you have any suggestions, I'd be
much obliged. Thanks!

"Graham Mayor" wrote:

You don't have a form field called Text1 or in the case of the
second macro Text2. Change the names to match your field names.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


inay wrote:
Hi Greg

When i test the below script by inserting it into a word document i
get an error message 'requested collection not available'. Do you
know what might be causing this?

Thanks,
Yani

"Greg" wrote:

Patricia,

Here is a few macro options that you set to run on exit from the
formfield that should give you a start:

Sub Format()
Dim oDoc As Document
Set oDoc = ActiveDocument
If oDoc.FormFields("Text1").Result "50" Then
oDoc.FormFields("Text1").Range.Font.Color = wdColorBrightGreen
Else
oDoc.FormFields("Text1").Range.Font.Color = wdColorAutomatic
End If
End Sub
Sub ColorField()
Dim content As String
With ActiveDocument.FormFields("Text2")
content = .Result
Select Case LCase(content)
Case "yes":
.Range.Font.Color = wdColorGreen
Case "no":
.Range.Font.Color = wdColorRed
Case Else:
.Range.Font.Color = wdColorAutomatic
End Select
End With
End Sub



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form Fields lose bold formatting Ellen Microsoft Word Help 0 February 17th 05 10:11 PM
Formatting Ellen New Users 2 February 9th 05 11:29 PM
how can I merge print and keep the conditional formatting Bob M Mailmerge 1 December 15th 04 03:32 PM
formatting links from excel into word (extra line feeds) JGT Microsoft Word Help 1 December 9th 04 12:01 PM
Apply Style but keep direct formatting? Stefan Blom New Users 2 November 29th 04 12:30 AM


All times are GMT +1. The time now is 02:53 AM.

Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright 2004-2023 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"