PDA

View Full Version : MS WORD 2k7 Table content change event



hak_888
01-28-2012, 03:10 AM
Hey guys,

I'm newbie in VBA, and I faced the problem, I have a word document with two tables. My requirement is, when content is changing in first table, second table's content should be updated as well ( automatically of course :) ). So I'm trying to find some event, that will be fired up, when content changes in the table, but can't find any so far. Is there such an event, or is there some workaround you can suggest ? Right now I'm handling Document Close event and performing required actions there, thou I think there may be more neat solution. Any kind of help would be appreciated.
Thanks in advance.

fumei
02-03-2012, 08:38 PM
There is no such event. If the content is numeric, and this is important, perhaps consider Excel.

If the content is text..waaaaaay more detail is needed to suggest a possible solution.

hak_888
02-04-2012, 02:18 AM
Let's say I have a simple table with two columns, Name and LastName, and few rows. On the document, there is another table, the clonse of the first one. So every time I'm changing content in the first table ( adding new records ) the second table's content should be changed accordingly, the same record should be inserted in the second table. So what you'd suggest ?

Frosty
02-04-2012, 01:16 PM
Why would you want to have two tables exactly the same in the same document?

If you really really want a clone... you can select the entirety of your first table, insert a book mark, and then wherever the "clone" table is... insert a "REF" field. It will update whenever fields update (Print Preview, opening the document, etc).

But I'm guessing you don't actually want a full clone of the table.

If you're looking for an actual event... you could use the WindowSelectionChange event. But that is a much bigger event than you originally stated. You could winnow it down to only doing any action when your selection is within the table, but you may see a pretty heavy "footprint" when doing that.

If you're completely lost on the above, I'd probably recommend explaining a bit more on what you want specifically, rather than hypothetical scenarios. Because, in your hypothetical scenario, I would say use Access or Excel. ;)

Frosty
02-04-2012, 01:20 PM
If neither of the above work, you should check out...
http://gregmaxey.mvps.org/word_tips.html

There are a number of tricks and resources there which may help you.

Specifically, if you're using Word 2007, you have content controls available to you as well, so that may be another avenue (although, be warned, content controls in 2007 have bugs which have been fixed in 2010)