none
Using Windows Form to add text to richtextcontentcontrol in Word document RRS feed

  • Question

  • Hi everybody,

    I'm building a project in which I want to add text to a richtextcontentcontrol in word by clicking a button on a random windows form.

    I want to 'pass' de text to the word document, which is added in the project in Visual Studio.

    In the provided link, the documents are included.

    https://www.dropbox.com/sh/kwhevbxyvn0ic77/AACXF1qW12vVlGuCXMDFqj-la?dl=0

    Thanks in advance!

    Monday, December 18, 2017 3:15 PM

All replies

  • Hello,

    I have downloaded your project but I'm still wondering how do you use the form in the project?

    I think the process is Getting the text->Getting the control object->Setting the text to the control object, right? Which part code puzzles you?

    I think the key point maybe how to access the richtextcontentcontrol. If so, I would suggest you set a tag for the control, such as "Test". And then you could use SelectContentControlByTag method to return the object and then set text to the object.

    Here is a simply code.

    //not sure how would you get the document object, you could get it by your way
    	    Word.Document wdDoc = Globals.ThisDocument.Application.ActiveDocument;
                Word.ContentControl contentControl = wdDoc.SelectContentControlsByTag("Test")[1];
                contentControl.Range.Text = "This is added text string";

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 19, 2017 3:10 AM