Insert paragraphs and tables in docx file using Word VSTO 2010 RRS feed

  • Question

  • Hello,

    I'm using Word.Interop api using C#.

    I'm using wordApp.Application.Selection.Range to insert text and tables sequentially(one after another) but selection still remains on the top of the document. My code is as below:

    wordApp.Application.Selection.Range.Text = "\r\n" + str;
    wordApp.Application.Selection.MoveDown(ref missing, ref cntfor, ref missing);

    wordApp.Application.Selection.Range.Text = "\r\n" + str;

    but above code insert text always at the top of the document.

    I want to create a document as below:




    Friday, May 1, 2015 1:40 PM


  • Hi Saurabh,

    >> but above code insert text always at the top of the document.

    Could you share us have your selected an area in the document? In my option, the Selection Object represents the current selection in a window or pane. A selection represents either a selected area in the document, or it represents the insertion point if nothing in the document is selected. I made a simple test like your code, and if you did not select any area and set the cursor at the top of the document, the test would be added at the top of the document. For inserting Text into Word, you could refer the link below:

    # How to: Programmatically Insert Text into Word Documents

    In addition, for inserting tables, I will recommend you post a new thread for this, then we could keep focus on the question, and for people who have the similar question, it would be easier for them to find the answer from a specific thread.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 4, 2015 9:40 AM