Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-22-2012, 08:52 AM
mpdsal mpdsal is offline Update Word table based on another table input Windows XP Update Word table based on another table input Office 2007
Novice
Update Word table based on another table input
 
Join Date: Nov 2011
Posts: 19
mpdsal is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 10-22-2012, 07:15 PM
macropod's Avatar
macropod macropod is offline Update Word table based on another table input Windows 7 64bit Update Word table based on another table input Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 10-22-2012, 09:35 PM
mpdsal mpdsal is offline Update Word table based on another table input Windows XP Update Word table based on another table input Office 2007
Novice
Update Word table based on another table input
 
Join Date: Nov 2011
Posts: 19
mpdsal is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 10-22-2012, 09:50 PM
macropod's Avatar
macropod macropod is offline Update Word table based on another table input Windows 7 64bit Update Word table based on another table input Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 10-22-2012, 10:54 PM
mpdsal mpdsal is offline Update Word table based on another table input Windows XP Update Word table based on another table input Office 2007
Novice
Update Word table based on another table input
 
Join Date: Nov 2011
Posts: 19
mpdsal is on a distinguished road
Default

"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
Reply With Quote
  #6  
Old 10-22-2012, 11:01 PM
macropod's Avatar
macropod macropod is offline Update Word table based on another table input Windows 7 64bit Update Word table based on another table input Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #7  
Old 10-25-2012, 10:13 AM
mpdsal mpdsal is offline Update Word table based on another table input Windows XP Update Word table based on another table input Office 2007
Novice
Update Word table based on another table input
 
Join Date: Nov 2011
Posts: 19
mpdsal is on a distinguished road
Default

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
Reply With Quote
  #8  
Old 10-25-2012, 02:21 PM
macropod's Avatar
macropod macropod is offline Update Word table based on another table input Windows 7 64bit Update Word table based on another table input Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #9  
Old 10-26-2012, 07:58 AM
mpdsal mpdsal is offline Update Word table based on another table input Windows XP Update Word table based on another table input Office 2007
Novice
Update Word table based on another table input
 
Join Date: Nov 2011
Posts: 19
mpdsal is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
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.
Unless I am missing something, when you select a cell within a table and use the copy/paste function it only pastes the related text not the background format. I find this strange. Also if you use bookmarks it only references the text of the cell none of the shading.

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
Reply With Quote
  #10  
Old 10-26-2012, 07:01 PM
macropod's Avatar
macropod macropod is offline Update Word table based on another table input Windows 7 64bit Update Word table based on another table input Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by mpdsal View Post
Unless I am missing something, when you select a cell within a table and use the copy/paste function it only pastes the related text not the background format.
My Bad - I was thinking that one of the PasteAndFormat options preserved shading info. Nevertheless, you could use something like:
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:
Also if you use bookmarks it only references the text of the cell none of the shading.
Not so if you're replicating the entire table. Furthermore, if you bookmark an entire cell, the entire cell will be replicated, including its borders & shading in the cross-reference.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 10-29-2012, 07:40 AM
mpdsal mpdsal is offline Update Word table based on another table input Windows XP Update Word table based on another table input Office 2007
Novice
Update Word table based on another table input
 
Join Date: Nov 2011
Posts: 19
mpdsal is on a distinguished road
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes


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
Update Word table based on another table input 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
Update Word table based on another table input 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft