Consulting

Results 1 to 6 of 6

Thread: Update word table based on another table input

  1. #1
    VBAX Regular
    Joined
    Apr 2012
    Posts
    17
    Location

    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. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cross-posted at: http://www.msofficeforums.com/word-v...ble-input.html
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    1. Please do not cross-post.

    2. "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?"

    Automatically? No, something will have to cause execution.

    I am not following the need to count rows.
    Last edited by fumei; 10-22-2012 at 08:11 PM.

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    One could hook into the Document.SelectionChange Event (see http://msdn.microsoft.com/en-us/libr...ionchange.aspx) but, as I noted in the cross-posted thread, the project:
    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.
    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 over come 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]

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    To meet the requirements mentioned by macropod (the adding/deleting before/after logic for table rows) will take precise thinking. Possible, but it is convoluted. Lots of testing.

    Regarding Selection_Change, the is the ONLY (AFAIK) way with basic VBA to automaticly test for changes. And it would work when you made a change in C5. BUT....it would execute, wait fro it, for EVERY change. Anywhere. For any reason. Every character you type, anywhere. Any movement of the cursor (followed by a click, thus a change inSelection). So if that routine had a lot of code to run (due to the testing logic), that is a LOT of - pointless - calls to the routine. Less than 0.01% effective...just kidding. On large documents it would be way less than that.

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    I think the very first test would have to be for .Information(wdWithInTable). If not, exit. Then you'd test which table. From there, it gets 'interesting'.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •