Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Format table cell based on text entry

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Newt - 01 Nov 2007 20:18 GMT
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?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.