2014-09-26 60 views
1

我正在閱讀tutorial on how to use control blocks to manipulate document in word
問題陳述:c#office開發:Microsoft.Office.Tools.Word.Controls.Button給出錯誤

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」不存在(是否缺少程序集引用? )C:\用戶\ ROOT \文檔\ Visual Studio 2010的\項目\ WordAddIn2 \ WordAddIn2 \ ThisAddIn.cs 14 45 WordAddIn2

+0

將錯誤代碼添加到您的問題。 – 2014-09-26 09:10:52

+1

'你錯過了一個程序集參考嗎?' - 是嗎? – 2014-09-26 11:41:48

+1

是的,你是。您需要添加C:\ Program Files \ Reference Assemblies \ Microsoft \ VSTO40 \ v4.0.Framework \ Microsoft.Office.Tools.Word.v4.0.Utilities.dll – 2014-09-26 11:51:42

回答

1

首先你需要Microsoft.Office.Tools.Word.v4.0.Utilities。 DLL。你有它嗎?

如果是的話, 在您的解決方案資源管理: 參考 - >添加引用 - >添加Microsoft.Office.Tools.Word.v4.0.Utilities引用到您的項目。

如果您在此步驟中會遇到一些錯誤,請閱讀Google中的「添加對Visual Studio項目的引用」。

+0

感謝您回答我的問題。以及這是我的壞toggleButton()方法,它是未完成的聲明。順便說一句,我已經初始化,但它仍然給出相同的錯誤信息。 – imeluntuk 2014-09-26 11:37:56

+0

我改變了我的答案。 – 2014-09-26 11:56:26

+0

非常感謝你luliia。它的作用就像魅力。 – imeluntuk 2014-09-26 14:14:07