【问题标题】:c# office development : Microsoft.Office.Tools.Word.Controls.Button giving errorc#office开发:Microsoft.Office.Tools.Word.Controls.Button给出错误
【发布时间】:2014-09-26 09:00:41
【问题描述】:

我正在阅读tutorial on how to use control blocks to manipulate document in word
问题是声明:

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

给出错误。

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

错误信息:

错误 1 ​​命名空间“Microsoft.Office.Tools.Word”中不存在类型或命名空间名称“Controls”(您是否缺少程序集引用?) C:\Users\root\Documents\Visual Studio 2010\项目\WordAddIn2\WordAddIn2\ThisAddIn.cs 14 45 WordAddIn2

【问题讨论】:

  • 在您的问题中添加错误代码。
  • are you missing an assembly reference? - 你是吗?
  • 是的,你是。您需要添加 C:\Program Files\Reference Assemblies\Microsoft\VSTO40\v4.0.Framework\Microsoft.Office.Tools.Word.v4.0.Utilities.dll

标签: c# ms-word add-in ribbon


【解决方案1】:

首先你需要 Microsoft.Office.Tools.Word.v4.0.Utilities.dll。你有吗?

如果是, 在您的解决方案资源管理器中: 参考-> 添加参考 -> 将 Microsoft.Office.Tools.Word.v4.0.Utilities 参考添加到您的项目。

如果您在此步骤中遇到错误,请阅读 Google 中的“添加对 Visual Studio 项目的引用”。

【讨论】:

  • 感谢您回答我的问题。好吧,这是我对 toggleButton() 方法的不好,这是未完成的声明。顺便说一句,我已经初始化了它,但它仍然给出相同的错误消息。
猜你喜欢
  • 2019-11-01
  • 1970-01-01
  • 2012-02-11
  • 1970-01-01
  • 2019-05-06
  • 2011-08-09
  • 2020-06-21
  • 2017-01-22
  • 2013-10-14
相关资源
最近更新 更多