Search code examples
c#ms-wordadd-inribbon

c# office development : Microsoft.Office.Tools.Word.Controls.Button giving error


I'm reading a tutorial on how to use control blocks to manipulate document in word.
the problem is statement:

private Microsoft.Office.Tools.Word.Controls.Button button = null;

is giving error.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Word;

namespace SecondWordAddIns {
    public partial class ThisAddIn {
        private Microsoft.Office.Tools.Word.Controls.Button button = null; // error here

        private RichTextContentControl richTextControl = null;

        private void ThisAddIn_Startup(object sender, System.EventArgs e) { }
        private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { }
        internal void toggleButton() { }

        #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
    }
}

The error message:

Error 1 The type or namespace name 'Controls' does not exist in the namespace 'Microsoft.Office.Tools.Word' (are you missing an assembly reference?) C:\Users\root\Documents\Visual Studio 2010\Projects\WordAddIn2\WordAddIn2\ThisAddIn.cs 14 45 WordAddIn2


Solution

  • Firstly you need Microsoft.Office.Tools.Word.v4.0.Utilities.dll. Do you have it?

    If yes, In your Solution Explorer: References-> Add Reference -> add Microsoft.Office.Tools.Word.v4.0.Utilities reference to your project.

    If you will get some error at this step, read about "Adding reference to Visual Studio project" in Google.