+ Reply to Thread
Results 1 to 4 of 4

Copy a table from Word to Excel if table not always in same location in the document

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Copy a table from Word to Excel if table not always in same location in the document

    Hi,

    i have a situation where i have a word file. In this word file there are "tables" and i want to copy a specific table in this word file. Now, i have seen others copy tables in word using excel vba but they copy a "specific" table number like copy table(4) which copies i think the 4th table in the file. What if the table i want to copy is not always the 4th table........then how do icopy the correct table. Would bookmarking the table i want to copy help? THoughts?
    Last edited by 6StringJazzer; 10-08-2021 at 08:06 AM. Reason: better titles please

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,935

    Re: Copy a table from Word to Excel if table not always in same location in the document

    Bookmarking is one way of doing it.

    Insert a bookmark in the first cell of the table and call it something unique.
    You can then refer to the table directly using the bookmark.
    Please Login or Register  to view this content.

    You can also use the Title property.
    Right-click your table and click Table Properties to get the Table Properties dialog.
    Click the Alt Text tab, enter something unique in the Title field and click OK.

    Loop through the tables and check the title to see if it's the one you want, or put this in a function to return the table object.
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Copy a table from Word to Excel if table not always in same location in the document

    thanks for the information.

    Had another question related to the book marking.

    If i assign a book mark to the first cell of a table .......... and the table is not table 1....ie..not table(1)

    Then how do i copy the table? I would assume that somehow i need to identify what the table number is but how do i do this? This is kinda
    why i was wanting to do the bookmark thing.

    Is this why u suggested using tabletitles? It kinda sounded like you would use tabletitles instead of bookmarks.

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,935

    Re: Copy a table from Word to Excel if table not always in same location in the document

    In the code
    Please Login or Register  to view this content.
    the "Tables(1)" refers to the table within the range identified by the bookmark, which isn't the same as the table number within the document.
    As such it doesn't matter where in the document the bookmarked table is since the the identifier is the bookmark and it should always be Tables(1) of that range.

    To copy it, assign it to a variable
    Please Login or Register  to view this content.
    The you can perform any table operation on t

    Table titles are an alternative method. It's more code since you need to loop through all the tables in the document and look at the title to find the right one and you also can't use the bookmarks to check that all the tables are accounted for.
    I'd go with the bookmarks as a first choice.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 08-15-2015, 02:35 PM
  2. Copy excel table to word
    By rpinxt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-15-2013, 10:07 AM
  3. VBA/Excel approach for a Last Saved/Edited column in a table with rows of data!
    By ian128 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2013, 07:16 AM
  4. VBA Code to copy table from word into excel
    By sharonb888 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-03-2013, 02:15 AM
  5. Replies: 1
    Last Post: 02-03-2013, 09:05 AM
  6. copy table in a word to excel
    By naflas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2011, 10:24 PM
  7. Copy Table from Excel to Word thru VBA
    By R Agarwal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-11-2008, 12:55 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1