Hello all,

Very little experience with Macros but I have created a project plan
template containing various form fields and any number of macros (mainly via
the recorder with a bit of code tweaking). One of the text fields in the
table is a due date. Via VBA is there any way to highlight the date cell or
even the entire row by changing the background colour red when the date is
overdue? I guess this would be quite straight forward in Excel via
Conditional formating but I would really like to do it in Word.

Any help appreciated.

Thanks.

Paul.

Re: Conditional format a table cell (background colour) by Doug

Doug
Tue Aug 16 16:04:07 CDT 2005

Run a macro containing the following code (modified as necesssary for the
bookmark name assigned to the formfield) on exit from the formfield into
which the date is entered:

With ActiveDocument
.Unprotect
If .FormFields("Text1").result < Now Then
.FormFields("Text1").Range.Cells(1).Shading.BackgroundPatternColor =
wdColorRed
Else
.FormFields("Text1").Range.Cells(1).Shading.BackgroundPatternColor =
wdColorAutomatic
End If
.Protect wdAllowOnlyFormFields, NoReset
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
"Paul Brown" <paul.brown25@ntlworld.com> wrote in message
news:F5sMe.9418$CM.7031@newsfe7-win.ntli.net...
> Hello all,
>
> Very little experience with Macros but I have created a project plan
> template containing various form fields and any number of macros (mainly
> via the recorder with a bit of code tweaking). One of the text fields in
> the table is a due date. Via VBA is there any way to highlight the date
> cell or even the entire row by changing the background colour red when the
> date is overdue? I guess this would be quite straight forward in Excel via
> Conditional formating but I would really like to do it in Word.
>
> Any help appreciated.
>
> Thanks.
>
> Paul.
>



Re: Conditional format a table cell (background colour) by Paul

Paul
Tue Aug 16 16:20:54 CDT 2005


"Doug Robbins" <dkr@REMOVEmvps.org> wrote in message
news:ed5cNYqoFHA.2484@TK2MSFTNGP15.phx.gbl...
> Run a macro containing the following code (modified as necesssary for the
> bookmark name assigned to the formfield) on exit from the formfield into
> which the date is entered:
>
> With ActiveDocument
> .Unprotect
> If .FormFields("Text1").result < Now Then
> .FormFields("Text1").Range.Cells(1).Shading.BackgroundPatternColor
> = wdColorRed
> Else
> .FormFields("Text1").Range.Cells(1).Shading.BackgroundPatternColor
> = wdColorAutomatic
> End If
> .Protect wdAllowOnlyFormFields, NoReset
> End With
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP

Hi Doug,

Thanks for the response.

I get a compile error - expected expression? These 2 lines seem to be
causing the problem but could be the way I pasted it:

.FormFields("Text1").Range.Cells(1).Shading.BackgroundPatternColor =
.FormFields("Text1").Range.Cells(1).Shading.BackgroundPatternColor =

Can you help further?



Re: Conditional format a table cell (background colour) by Paul

Paul
Tue Aug 16 16:59:39 CDT 2005

Sorry it was my pasting - got it sorted now. Thanks very much.



Re: Conditional format a table cell (background colour) by Paul

Paul
Wed Aug 17 04:03:38 CDT 2005

The only problem is that whatever date I put in the cell (either future or
past) it formats the cell red. Have I missed something? Sorry to keep
troubling you with this.

Paul.