title: Excel Add-In C# get value of active cells
body: <p>I used the Visual Studio 2013 Add-In Template and made a custom task pane with a simple button it.  Now I am trying to read the value of the active cells when the button is pressed.  This is what I have so far:</p>
  
  <pre><code>    namespace CostCenterAddIn
      {
           public partial class CostCenterControl : UserControl
           {
               public CostCenterControl()
               {
                   InitializeComponent();
               }
  
               private void button1_Click(object sender, EventArgs e)
               {
  
                  Excel.Window W = this.Application.ActiveWindow as Excel.Window;
                  Excel.Range R = W.ActiveCell as Excel.Range;
                  MessageBox.Show(R.Text.ToString());
               }
           }
      }
  </code></pre>
  
  <p>I copied this example: <a href="https://stackoverflow.com/questions/1767338/read-the-activecell-content-in-excel-using-vsto">Read the ActiveCell content in Excel using VSTO</a></p>
  
  <p>However, I am getting the following error: </p>
  
  <p>'CostCenterAddIn.CostCenterControl' does not contain a definition for 'Application' and no extension method 'Application' accepting a first argument of type 'CostCenterAddIn.CostCenterControl' could be found (are you missing a using directive or an assembly reference?)   </p>
  
  <p>For some reason I can't access Application.</p>
  
  <p>This is my code for "ThisAddIn.cs":</p>
  
  <pre><code>    namespace CostCenterAddIn
      {
         public partial class ThisAddIn
         {
             private CostCenterControl myUserControl1;
             private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;
  
             private void ThisAddIn_Startup(object sender, System.EventArgs e)
             {
                this.Application.WorkbookBeforeSave += new                    Microsoft.Office.Interop.Excel.AppEvents_WorkbookBeforeSaveEventHandler(Application_WorkbookBeforeSave);
  
                myUserControl1 = new CostCenterControl();
                myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1, "Cost Center Converter");
                myCustomTaskPane.Visible = true;
             }
  
             private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
             {
             }
  
             #region VSTO generated code
  
             /// &lt;summary&gt;
             /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// &lt;/summary&gt;
            private void InternalStartup()
            {
               this.Startup += new System.EventHandler(ThisAddIn_Startup);
               this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
  
            #endregion
          }
       }
  </code></pre>
  
  <p>Any advice would be much appreciated!</p>