Results 1 to 5 of 5

Thread: add a row to a word table

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2008
    Posts
    20

    add a row to a word table

    Hello,

    I'm writing some info to a word document from my program. For this I am using a template, and a table.

    Now my question is, how can i dynamically add a row to the table BUT NOT AT THE END of the table, somewhere in between.

    (I know it's easy doing it at the end of the table, but i need it to be somewhere in the middle off the table.)

    any suggestions?

    I tried using the macro recorder, but i can't add rows in word in my table when macro recording is on

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: add a row to a word table

    vb Code:
    1. ActiveDocument.Tables(1).Rows.Add ActiveDocument.Tables(1).Rows(2)
    where rows(2) is the row where you want to insert

    I tried using the macro recorder, but i can't add rows in word in my table when macro recording is on
    you have to use the menu
    Last edited by westconn1; Dec 17th, 2008 at 05:57 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: add a row to a word table

    If your cursor is in the table somewhere you can do -

    vb Code:
    1. Selection.InsertRowsAbove 1

    or

    vb Code:
    1. Selection.InsertRowsBelow 1

    These will insert a row either above or below the row you have selected with your cursor !
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2008
    Posts
    20

    Re: add a row to a word table

    Thanks alot to both of you, you've helped me alot.

  5. #5
    New Member
    Join Date
    Feb 2018
    Posts
    1

    Resolved Re: add a row to a word table

    Quote Originally Posted by westconn1 View Post
    vb Code:
    1. ActiveDocument.Tables(1).Rows.Add ActiveDocument.Tables(1).Rows(2)
    where rows(2) is the row where you want to insert


    you have to use the menu
    Thanks I spend almost day trying all the options, This code helped me.

    Thanks
    Prasanna Sinthaje

Posting Permissions

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



Click Here to Expand Forum to Full Width