none
Created a Word 2007 Application level word add-in - does not work for new documents RRS feed

  • Question

  • I have created a Word add-in following the article here. I press F5 and run the project and It works as expected and I would think that the add-in has been installed in my machine. So, now I open another instance of Word 2007 and create a document and I dont see that code working on the new document. Am I missing something?

    Following is the code sample :-

     

     

     

        using Word = Microsoft.Office.Interop.Word;
    
        namespace WordAddIn1
        {
    
            public partial class ThisAddIn
    
            {
    
                private void ThisAddIn_Startup(object sender, System.EventArgs e)
    
                {
    
                    this.Application.DocumentBeforeSave +=
    
           new Word.ApplicationEvents4_DocumentBeforeSaveEventHandler(Application_DocumentBeforeSave);
    
                }
    
                private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    
                {
    
                }
    
                void Application_DocumentBeforeSave(Word.Document Doc, ref bool SaveAsUI, ref bool Cancel)
    
                {
    
                    Doc.Paragraphs[1].Range.InsertParagraphBefore();
                    Doc.Paragraphs[1].Range.Text = "----1ashish text was added by using code.---";
    
                }
    
                    #region VSTO generated code
    
                /// <summary>
    
                /// Required method for Designer support - do not modify
    
                /// the contents of this method with the code editor.
    
                /// </summary>
    
                private void InternalStartup()
                {
    
                    this.Startup += new System.EventHandler(ThisAddIn_Startup);
    
                    this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);   
    
                }
    
                #endregion
    
            }
    
        }

     

     

     

    From here:-When you finish developing a project, remove the add-in assembly, registry entries, and security settings from your development computer. Otherwise, the add-in will continue to run every time that you open Word on your development computer. To clean up the completed project on your development computer In Visual Studio, on the Build menu, click Clean Solution.

    Now, when I dont clean the solution, I should have the add-in for the Word 2007 all the time, right? I don't see that happening at all.


    • Edited by ashishmgupta Sunday, June 12, 2011 8:09 AM Added code sample
    Saturday, June 11, 2011 5:13 AM

Answers

  • I see that removing that add-in from word 2007 resolves the problem. If you face this problem, try removing the add-in from Word 2007 and build the solution the solution again and your change will take effect. For some reason "Clean solution" does not remove the word add-in sometimes (atleast sometimes in my case :-))

     

    enter image description here

    enter image description here



    • Marked as answer by ashishmgupta Sunday, June 12, 2011 4:01 PM
    Sunday, June 12, 2011 4:00 PM

All replies

  • I see that removing that add-in from word 2007 resolves the problem. If you face this problem, try removing the add-in from Word 2007 and build the solution the solution again and your change will take effect. For some reason "Clean solution" does not remove the word add-in sometimes (atleast sometimes in my case :-))

     

    enter image description here

    enter image description here



    • Marked as answer by ashishmgupta Sunday, June 12, 2011 4:01 PM
    Sunday, June 12, 2011 4:00 PM
  • Hi Ashishmgupta,

    Glad to hear that you have resolved the problem yourself and share the workaround with us. You are welcome.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 13, 2011 4:40 AM