none
How can I copy the content of the last page in a word document and paste it to a next page? RRS feed

  • Question

  • Hi everyone,

    I've built a document-level application using Word 2010 ( VSTO 4.0 ). When a user chooses  some authors from Action Pane and click Insert button, they will be inserted in the document. The problem is there are only two pages in my document which allow maximum 4 authors to be inserted. But I want the user can choose the number of authors they want to.

    How can I do that? 

    Monday, November 28, 2011 6:31 AM

Answers

  • Hi Cloudaga

    <<To answer your question, in my solution, "target areas" are plain text content controls. Even if I duplicate the sections, I still don't know how can I insert author information into them.>>

    As long as we're talking about the Word.Interop (rather than the VSTO objects) you can assign a value to content controls' Title and/or Tag properties after they've been inserted. Then you use the Document.SelectContentControlByTitle / Document.SelectContentControlByTag method to retrieve the content control(s) with the specified value.

    OR, you can simply address the controls by their index value in the document, picking up the last two (or in your case it appears there would be four); something like (pseudocode!):
    int nrCC = doc.ContentControls.Count;
    doc.ContentControls[nrCC];
    doc.ContentControls.[nrCC-1];


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Cloudaga Wednesday, November 30, 2011 4:06 PM
    Monday, November 28, 2011 9:18 AM
    Moderator

All replies

  • Hi Cloudaga

    May we assume that your document is a kind of "form", with two "form sections" per page?

    The standard Word approach would be to save a form section, or two form sections, as a "Building Block" entry and insert that Building Block entry whenever a new form section or sections is required.

    Building Blocks are stored in Word template files. A Template has the extension *.dotx (or *.dotm if it would contain VBA code).

    If users will be generating multiple documents from your VSTO solution, a template would be the correct type of VSTO document-level solution for your project and the Building Block could be stored in it. If you need a document type of document-level solution, then you could create a "plain" (not-VSTO) Word template to store the Building Block, distribute it with your solution and load it as required.

    An alternate approach would be to store the WordOpenXML for the "form section" as a string (resource, perhaps) and insert that into the document, as required, using the Range.InsertXML method.

    Yet another possible approach would be to duplicate the sections "on-the-fly", although I would use the Range.FormattedText property rather than Copy/Paste.

    No matter which approach you decide to use, you're going to run into a problem. I'm assuming that the "target areas" for the author information you're inserting into the "form sections" are some kind of VSTO control. A bookmark or a content control? VSTO controls cannot simply be "copied" or "inserted" using any of these methods. Only the underlying Word object will be pasted/inserted.

    So for a complete answer to your question, it would be helpful to know what kind of "target areas" you're using and what happens to the author information once it's been captured in the VSTO document?


    Cindy Meister, VSTO/Word MVP
    Monday, November 28, 2011 7:27 AM
    Moderator
  • Hello Cindy,

    To answer your question, in my solution, "target areas" are plain text content controls. Even if I duplicate the sections, I still don't know how can I insert author information into them. 

    Is it impossible to do this?

    By the way, my document is in the picture below. I want to insert more than 2 authors.
    • Edited by Cloudaga Monday, November 28, 2011 9:02 AM
    Monday, November 28, 2011 8:51 AM
  • Hi Cloudaga

    <<To answer your question, in my solution, "target areas" are plain text content controls. Even if I duplicate the sections, I still don't know how can I insert author information into them.>>

    As long as we're talking about the Word.Interop (rather than the VSTO objects) you can assign a value to content controls' Title and/or Tag properties after they've been inserted. Then you use the Document.SelectContentControlByTitle / Document.SelectContentControlByTag method to retrieve the content control(s) with the specified value.

    OR, you can simply address the controls by their index value in the document, picking up the last two (or in your case it appears there would be four); something like (pseudocode!):
    int nrCC = doc.ContentControls.Count;
    doc.ContentControls[nrCC];
    doc.ContentControls.[nrCC-1];


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Cloudaga Wednesday, November 30, 2011 4:06 PM
    Monday, November 28, 2011 9:18 AM
    Moderator
  • Hi Cindy,

    Thank you for your answer. As you can see in my picture, my document only can insert 2 authors. Is there any way that I can insert more than 2 authors? How can I select and duplicate (Copy/Paste) *it*?

    Monday, November 28, 2011 1:39 PM