#1
|
|||
|
|||
Update Word table based on another table input
Greetings.
I am using Word 2010 and I want to perform the following action in a specific cell(s) within a Word table. My word doc contains 5 different tables. I will manually update the cells in table 5 but I want to automatically update the contents of table 3. For example: Table 5, cell 3 (C3) contains the text "GREEN" with a green colored background. Table 5 has 12 rows and 3 columns. I want Table 3, cell 3 (C3) to be populated with the same text and format as Table 5 (C3). In addition, I may add or delete a row from each table. Is there a way of using VBA to perform the update noted above AND count the rows on each pass so that it runs until it hits the last row whether the table contains 1 or n number of rows? I hope I have stated this clearly enough. I can submit the document if that would help. Thanks |
#2
|
||||
|
||||
Cross-posted at: http://www.vbaexpress.com/forum/showthread.php?t=44074
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
My apologies. I didn't know that these forums were related. I wasn't sure which forum was more applicable to my question.
Regards, Mark |
#4
|
||||
|
||||
There's no connection: providing links is just a common courtesy, so that people in one forum don't waste time trying to cover the same ground that's been covered elsewhere.
As it is, I think what you're asking for would require some fairly involved vba programming, especially if Word's supposed to figure out what's supposed to happen when rows are added or deleted.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
"As it is, I think what you're asking for would require some fairly involved vba programming, especially if Word's supposed to figure out what's supposed to happen when rows are added or deleted. "
It may, however I think the use of a counter within a loop may reduce the code to perform this. So I hope. I will leave it in the capable hands of the experts should someone attempt to solve. Thanks again for the heads up. Mark |
#6
|
||||
|
||||
And what if you add/delete a row above the existing one? How is Word going to keep track of what's going on? Sure, it might be able to for the current session, but as soon as you close the file, it'll forget all it knew about what had been going on. To overcome that, you'd need to create & store the relevant content in a document variable or something such. Gets real complicated once you start moving rows around ...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
I figured it out for changing background. It seems to work. Any modifications suggested will be taken into consideration. Appreciate everyone who contributed.
Sub CopyBackground() Dim myCells As Range Dim celTable As Cell Dim I As Long Dim J As Long I = ActiveDocument.Tables(7).Rows.Count J = ActiveDocument.Tables(4).Rows.Count For N = 1 To I Set celTable = ActiveDocument.Tables(7).Cell(N, 3) ActiveDocument.Tables(4).Cell(N, 3).Shading.BackgroundPatternColor = celTable.Shading.BackgroundPatternColor Next N End Sub |
#8
|
||||
|
||||
You could use a simple copy/paste to replicate the entire cell's contents. However, that still doesn't address the automation issue or the problems associated with addong/deleting rows.
Of course, if the second table is supposed to replicate the first one entirely, simply bookmark the first one and use a cross-reference for the second table.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Quote:
As for the automation, if you notice I use a variable for a counter to check the number of rows in a table. If rows are added or deleted it will be reflected in that count and when the total is reached the program ends. I am receptive to improvements if anyone has one. Thanks1 |
#10
|
||||
|
||||
Quote:
Code:
Sub Demo() Dim lBkClr As Long, lFrClr As Long, i As Long With ActiveDocument.Tables(1).Range For i = 1 To .Cells.Count With .Cells(i) .Range.Copy lBkClr = .Shading.BackgroundPatternColor lFrClr = .Shading.ForegroundPatternColor End With With ActiveDocument.Tables(2).Range.Cells(i) .Range.Paste .Shading.BackgroundPatternColor = lBkClr .Shading.ForegroundPatternColor = lFrClr End With Next End With Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
Paul,
I'll give your code a try. I must only have the text Bookmarked in that case. I'll play around some more with utilizing Bookmarks to capture all settings for a cell. Thanks again. Mark |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Linking excel table to powerpoint for easy update | atwood121 | PowerPoint | 0 | 05-11-2012 07:09 AM |
How do I dynamically update data in a Word Document from a database table | RSchmidt | Word | 1 | 07-14-2011 04:27 PM |
Table update in running presentation | rumdrum | PowerPoint | 0 | 02-10-2011 01:28 PM |
SOS - cannot update table of content properly | Lee | Word | 5 | 02-04-2011 12:59 PM |
Easy Update "Table of Contents" feature in Microsoft Word 2007 VS. Word 2010 | Xarzu | Word | 0 | 09-22-2010 06:54 PM |