Is it possible to format a cell in a table as soon as a user starts entering
text? Here's what I'd like:
1. Cell starts with no text and has light yellow background
2. User begins typing, which turns the background white
Basically, I'd like something the same as conditional formatting in Excel
(embedding a spreadsheet is not an option).
Here's what I was trying, but it doesn't work:
Private Sub celltext()
If ActiveDocument.Tables(2).Cell(1, 2).Range.Text = "" Then
ActiveDocument.Tables(2).Cell(1, 2).Shading.BackgroundPatternColor =
wdColorLightYellow
Else
ActiveDocument.Tables(2).Cell(1, 2).Shading.BackgroundPatternColor =
wdColorWhite
End If
End Sub
I see two problems. One, I can't seem to get it to read the text in the cell
and two, I don't think that starting to type in a cell is a trigger to
activate the code. Any ideas?
macropod - 02 Nov 2007 09:46 GMT
Hi Newt,
Word doesn't have the same kind of event-driven functionality that you have in Excel, so you need to do something to cause the macro
to run. You could, for example, insert a macrobutton field to trigger the macro, or you could use a formfield to trigger the macro
and protect your document for forms.
Cheers

Signature
macropod
[MVP - Microsoft Word]
-------------------------
> Is it possible to format a cell in a table as soon as a user starts entering
> text? Here's what I'd like:
[quoted text clipped - 20 lines]
> and two, I don't think that starting to type in a cell is a trigger to
> activate the code. Any ideas?
Newt - 02 Nov 2007 19:13 GMT
Thanks for the response. I guess I should consider building it in Excel.
> Hi Newt,
>
[quoted text clipped - 27 lines]
> > and two, I don't think that starting to type in a cell is a trigger to
> > activate the code. Any ideas?