none
ContentControlOnEnter event is not firing RRS feed

  • Question

  • Hi All,

    I have a master document with some contentcontrols in it. In my add-in when I am clicking a menu called "New Document", programmatically opening the existing master document and copying all the contents and pasting in the new document. After doing this, I am setting the ContentControlOnEnter and Exit events for the document. this is not triggering the events at all. But if I save the document and reopen the same, it works perfectly, but as per the requirements I should not save the new document created till the user wants to save it.

    It will be nice if you guys can suggest a way to resolve this issue.

    Thanks,

    Sree

    Wednesday, July 6, 2011 1:26 PM

Answers

  • Hi Sree

    Mmm, let's back up a step and work on the program logic. Copying/pasting the content of a "master document" is something I'd only do as a last resort, if no other approach is possible. Usually, for the kind of thing you describe, I'd use the WordApplication.Documents.New() method to create a new, identical document from the "master". Without opening it (danger of changes!); without cluttering the user's Clipboard... AND it should also include all the code from the "master".

    Is there any reason you're not doing that?


    Cindy Meister, VSTO/Word MVP
    Wednesday, July 6, 2011 4:17 PM
    Moderator
  • Hi Meister,

    That is a wonderful suggestion. I could not find  WordApplication.Documents.New(), so I saved my master document as dotx file. used the below code to create the new doc from that.

    Application.Documents.Add(ref masterTemplateFile)

    This resolved my issue. Thanks a lot for your wonderful idea.

    Thursday, July 7, 2011 4:07 AM

All replies

  • Hi Sree

    Mmm, let's back up a step and work on the program logic. Copying/pasting the content of a "master document" is something I'd only do as a last resort, if no other approach is possible. Usually, for the kind of thing you describe, I'd use the WordApplication.Documents.New() method to create a new, identical document from the "master". Without opening it (danger of changes!); without cluttering the user's Clipboard... AND it should also include all the code from the "master".

    Is there any reason you're not doing that?


    Cindy Meister, VSTO/Word MVP
    Wednesday, July 6, 2011 4:17 PM
    Moderator
  • Hi Meister,

    That is a wonderful suggestion. I could not find  WordApplication.Documents.New(), so I saved my master document as dotx file. used the below code to create the new doc from that.

    Application.Documents.Add(ref masterTemplateFile)

    This resolved my issue. Thanks a lot for your wonderful idea.

    Thursday, July 7, 2011 4:07 AM
  • My mistake - end of a long day - yes, of course it's the Documents.Add method. Glad you figured that out and that things are working :-)!
    Cindy Meister, VSTO/Word MVP
    Thursday, July 7, 2011 8:52 AM
    Moderator