Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
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
![]() |
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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 | |
|
|
![]() |
||||
Thread | Forum | |||
Form Fields lose bold formatting | Microsoft Word Help | |||
Formatting | New Users | |||
how can I merge print and keep the conditional formatting | Mailmerge | |||
formatting links from excel into word (extra line feeds) | Microsoft Word Help | |||
Apply Style but keep direct formatting? | New Users |