none
Apply Document-Level Add-In to Existing Documents

    Question

  • We currently have a process for extracting specific parts from Word documents where a user opens the document and marks the relevant pieces then runs an external program on that document. That application extracts the marked parts. The external application (C# and Office interop) can be picky about how things were marked and users are not very fond of using it.

    I thought maybe we could write an add-in for Word that would be easier to use. The idea would be that a user would open the document, select ranges of text and then click a button on a CustomTaskPane. The application would keep a list of the selected ranges. When the user is finished , they could click another button to export the text ranges.

    My first attempt was an Application-Level add-in that worked wonderfully until I opened a second instance of Word. I then realized why Document-Level add-ins exist, the list of ranges is shared between open documents. So my next attempt was to create a Document-Level add-in and that worked for new documents. So now I want to know if I can somehow apply this add-in to existing documents.

    As I see it, I have three options in order of increasing preference:

    1. Use an Application-Level add-in and tell users they can only have one document open at a time. Not ideal from the usability perspective.
    2. Use an Application-Level add-in and implement DocumentOpen event handlers to implement a "pseudo-document scoped" data layer. Not ideal because it seems like a fragile design.
    3. Use a Document-Level add-in and figure out how to apply it to existing documents.

    Document-Level makes sense in my case since I have document specific data that I want to track but applying it to existing documents is a definite must.

    What is my best option here? Can Document-Level add-ins be applied to existing documents? If so, how?

    We are using Office 2013 and 2016.

    • Edited by FamousJameous Thursday, February 08, 2018 4:28 PM Add info about office versions.
    Thursday, February 08, 2018 4:23 PM

Answers

All replies

  • Well, I think I managed to add my Document-Level customization to an existing document using the information in this link: https://msdn.microsoft.com/en-us/library/bb772091.aspx.

    I had to create another application that takes the paths for the .docx and the .vsto and applies the customization. Is that my best option? I don't really like the idea of having the user run an external program just to enable the new functionality, but I suppose it isn't that big of an inconvenience.

    Thursday, February 08, 2018 9:05 PM
  • Hi FamousJameous,

    You had mentioned that,"my next attempt was to create a Document-Level add-in and that worked for new documents. So now I want to know if I can somehow apply this add-in to existing documents."

    Do you mean that you created the Document level project with new document and you want to include another document?

    You can select the existing document when you create a project.

    If you think that you had already found the solution in that link that you had shared in your last post then I suggest you to mark your last post as an answer.

    Regards

    Deepak


    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.

    Friday, February 09, 2018 5:15 AM
    Moderator
  • Hi Deepak,

    What I meant by that statement was that I wanted to create the Document Level project, publish it and then users could apply it to any documents they want.

    My reply was to say that I found one way to do that: by creating another application that would apply the Document Level project to documents. However, I would still like to know if there is a "better" way. I don't really want my users to have to run one application just to enable the actual functionality that I am trying to implement.

    If there is no better answer, the method described in my reply is the best option I have so far so I will mark that as the answer.

    Thanks

    Friday, February 09, 2018 3:09 PM
  • You need to develop an application-level COM add-in instead. See Walkthrough: Creating Your First VSTO Add-in for Word to get started quickly. 

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Monday, February 12, 2018 12:20 AM
  • Thanks Eugene,

    As I mentioned, I have already developed an Application Level add-in but that means that if the user opens multiple documents the add-in's state data will be shared between them. Do you suggest I implement option 2 from my original post, or do you have another suggestion?

    Monday, February 12, 2018 3:38 AM
  • You need to follow the option #2 described above. Handle the DocumentOpen event of the Application where you can work with a document opened. Please remember that you can save information to the CustomDocumentProperties. See How to: Create and Modify Custom Document Properties for more information.  

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers


    Monday, February 12, 2018 8:15 AM
  • Thanks Eugene, I will move forward with option #2.

    Out of curiosity, what is the difference between document Variables and CustomDocumentProperties? I have been using Variables to store state data in the document in order to reload the state when the user opens the document later.  I have been searching for the difference, but haven't yet found an answer.

    Monday, February 12, 2018 3:37 PM
  • Users can see/change properties, and string properties have a max length of 255.
    Tuesday, February 13, 2018 7:19 PM