+ Reply to Thread
Results 1 to 8 of 8

adding rows into word document

  1. #1
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    adding rows into word document

    Hello

    Could anybody help me, how to add rows to an existing word-table from excel vba and how to put value enter into it?

    Maybe it it easier to create a completely new table, but number of the rows is not constant, it depends of the content of table where I want to copy these data from.

    many thanks

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: adding rows into word document

    Use Word's builtin importfacilities.

    Please Login or Register  to view this content.
    You can also link an Excel file to a Word document so that it will be updated automatically.


    If the Word document doesn't exist already:
    Please Login or Register  to view this content.
    Last edited by snb; 07-17-2011 at 11:45 AM.



  3. #3
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: adding rows into word document

    Thanks.
    I think, I didn't specify my question carefully enough.
    What I want to do is to complete a word document based on a dot, which has different tables.
    The values are coming from an excel table, the target table will have at least one row, but maybe more.
    The first row of the table can be completed with bookmarks or docvariables, but I have to solve, that in case the mastersheet has more rows concerning the given document, then these will be also in the word in new rows in the same table.
    I do not have to copy the entire row from the excel sheet, but a few cells only.

    Thank you

  4. #4
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: adding rows into word document

    Hi Harry
    I used the following in an earlier project .. it may help some

    Please Login or Register  to view this content.
    This code snippet inserts two rows above row 4 in an existing table, Table 1 in the document object TgtRepWdDoc.
    Note that "objWord" is the object instance of Word running within Excel VBA.
    You need to specify this to qualify the keyword "Selection" otherwise Excel complains.
    There is also an "InsertRowsBelow" method.

    And to add text (e.g. to row 4 and col 3; and then two cells to the right) ..
    Please Login or Register  to view this content.
    Hope this gets you going
    Barry
    Last edited by barryleajo; 07-17-2011 at 02:10 PM.

  5. #5
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: adding rows into word document

    Many thanks, this works.
    I found another way to add text into these word cells, maybe it is useful to share it with you as well.

    Please Login or Register  to view this content.
    thanks again

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: adding rows into word document

    I don't believe this code works:
    You can't select a table that hasn't been been inserted.

    And if you can you should avoid using 'select' in VBA.

    Your code contradicts your earlier assertion that you have to expand an existing table.

    You didn't learn from my earlier code that
    Please Login or Register  to view this content.
    is unnecessarily complicated and can re replaced by:

    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: adding rows into word document

    Thanks Harry
    ...obvious when you point it out ...
    Glad you're sorted now.
    By the way I have found that within your loop:
    Please Login or Register  to view this content.
    can be restated as:
    Please Login or Register  to view this content.
    I think Range in this context refers to a portion of the document.
    Since you are in a Table then this doesn't apply, presumably because the table has already been positioned within the document?
    If you are all done on this then mark your thread as Solved?

  8. #8
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: adding rows into word document

    Yes, you're right, select should be avoided, but currently I don't see other option..
    It does what I want it to do.
    I don't see, why do you think that it contradicts with expansion of an existing table?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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