The Anchorage
Personal website of Gregory K. Maxey, Commander USN (Retired)
The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.
However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.
If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!
This Microsoft Word Tips & Microsoft Word Help page demonstrates a method that you can use to create "custom" table cell "OnEnter, OnChange and OnExit" events using VBA procedures. You can download a demonstration document using the link at the end of the page.
While the examples I show here may appear simplistic, implementing this method in a practical application requires extensive planning, thought and work; and a fairly good understanding VBA. I feel that the potential benefit of real time evaluation of user entered data in certain applications may be worth the extra time, thought and effort.
Before going any further I want to give some credit where credit is due. The "master key" to the entire method is a relatively simple (now simple to me at least) procedure to monitor a range object for change. I was introduced to that method by Jeff Vandervoort and first applied it in my Content Control Custom Events tips page. Jeff participates in the Microsoft Office Word for Developers forum and without his skills and his willingness to share the fruits of those skills this tips page would not be published. I would also like to thank Jason Frost Simpson, a regular in the VBA Express forum, for suffering eye strain to read my unconventionally structured code and providing valuable suggestions for improvement.
The cell events are defined as follows:
For the demonstration I will be using a Word 2010 document containing three tables.
Note. The illustrations in this tips page may or may not reflect the appearance or arrangement of the actual demonstration document.
The first demonstration utilizes a singe cell table and illustrates all three events.
The basic demonstration should illustrate a solution to a common request. "How can I limit the amount of text a user can enter into a table cell?" You will of course have to change the action on each event to suit your particular need.
In Table 2 below:
With thought and planning you can take advantage of the events to perform real time processing of data user enter into table cells. Table 3 below illustrates a small excerpt from a invoice template that I have developed. Calculation are performed automatically in real time as the user changes quantity or price.
You can download the complete demonstration document here: Table Cell Change Events Demo
That's it! I hope you have found this tips page useful and informative.
The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.
However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.
If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!