+ Reply to Thread
Results 1 to 4 of 4

Word macro to copy table from excel

Hybrid View

  1. #1
    Registered User
    Join Date
    11-24-2012
    Location
    Kolkata
    MS-Off Ver
    Excel 2007
    Posts
    2

    Word macro to copy table from excel

    I have a word document with some tables. Now the tables are actually copied from excel. The formatting of the tables in word is different from that in excel.

    I need to develop a macro which can access the tables in excel and update the same in word, without changing the formatting of the table in word.

    The new table from excel may have a few rows more or a few rows less that the old table in word which it should replace.

    I have developed a code which manages to bring in the new tables from excel, but the formatting is an issue.

    What I have done is marked the tables in word as bookmarks. I have an excel sheet where the bookmark is associated with a specific range (passed through 'range' variable ) from a specific sheet(passed through Sheet_name variable) in another excel tab where the tables are present.


    The code is given below. Please suggest a way to achieve the desired outcome.


    For Each bmk In ActiveDocument.Bookmarks

    vBookmarks(j) = bmk.Name
    j = j + 1

    Next bmk


    For x = 0 To j - 1

    table_num = Val(Right$(vBookmarks(x), 2))

    MsgBox (table_num)

    Selection.GoTo What:=wdGoToBookmark, Name:=vBookmarks(x)
    Selection.Cut
    objWbk.Worksheets(Sheet_name).Range(range).Copy
    Selection.PasteExcelTable False, True, True

    'now reinstate the bookmark

    objDoc.Bookmarks.Add Name:=vBookmarks(x), Range:=ActiveDocument.Tables(table_num).Range

    Next x



    Thanks in advance!!!

  2. #2
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: Word macro to copy table from excel

    Hi
    If I understand you correctly you do not need a macro for this. If the cells in Excel are static all you need to do is copy and paste a link in your Word Table. Then when anything changes in those linked cells they will be updated in your Word document (even if it is not open).
    Hope this helps.
    Good luck.
    Tony

  3. #3
    Registered User
    Join Date
    11-24-2012
    Location
    Kolkata
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Word macro to copy table from excel

    Quote Originally Posted by ARGK View Post
    Hi
    If I understand you correctly you do not need a macro for this. If the cells in Excel are static all you need to do is copy and paste a link in your Word Table. Then when anything changes in those linked cells they will be updated in your Word document (even if it is not open).
    Hope this helps.
    Good luck.
    Tony
    Thanks a lot for your reply......

    The thing is that the size of the tables in excel may change.....

    Suppose my current excel and word table has 7 rows....now it may so happen that the number of rows in the table in excel is increased to say 10.....will that be updated in the word??? Similarly, the number of rows may decrease as well......
    Last edited by nishant_88; 08-06-2013 at 02:35 PM.

  4. #4
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: Word macro to copy table from excel

    Hi
    If there is a "maximum" number of rows in your Excel document then you could copy and paste a link to the maximum size of your table and that will work for you. If this is not sufficient then you will need someone to write some VBA for you.
    Tony

+ 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. [SOLVED] copy excel cell to cell in word table using excel macro
    By jthurnwps in forum Excel General
    Replies: 1
    Last Post: 07-08-2014, 01:17 AM
  2. macro to copy excel data into word table
    By steve61 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-08-2013, 08:02 AM
  3. Macro to copy data from Excel cells to table in word
    By krkrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-08-2013, 11:27 PM
  4. 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
  5. Macro excel to copy and paste table from Word
    By Shunlee in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-16-2008, 06:52 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