2012-06-12 113 views
1

我是Excel插件程序設計新手。我在C#中爲Excel 2010創建了一個Excel插件,它將在每張工作簿中創建按鈕。Excel加載項按鈕

有人能告訴我什麼是錯,此代碼:

Excel.Worksheet activeWorksheet = Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet; 
Microsoft.Office.Tools.Excel.Worksheet vstoWorksheet = activeWorksheet.GetVstoObject(Globals.Factory); 
Excel.Range selection = vstoWorksheet.Range[2, 2]; 
Microsoft.Office.Tools.Excel.Controls.Button button = new Microsoft.Office.Tools.Excel.Controls.Button(); 
button.Tag = vstoWorksheet.Controls.AddControl(button,selection, "Click"); button.Name = "Click"; 
button.BackColor = System.Drawing.Color.Cyan; 
button.Text = "Click"; 
+1

微軟大約有一個整體網站它在這裏http://msdn.microsoft.com/en-us/office/hh133430.aspx – Jesse

+0

Excel.Worksheet activeWorksheet =Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet; Microsoft.Office.Tools.Excel.Worksheet vstoWorksheet = activeWorksheet.GetVstoObject(Globals.Factory); Excel.Range selection = vstoWorksheet.Range[2, 2]; Microsoft.Office.Tools.Excel.Controls.Button button = new Microsoft.Office.Tools.Excel.Controls.Button(); button.Tag = vstoWorksheet.Controls.AddControl(button,selection, "Click"); button.Name = "Click"; button.BackColor = System.Drawing.Color.Cyan; button.Text = "Click"; 有人可以告訴我這段代碼有什麼問題。 – Abhinav

回答

0

我看到的問題:

button.Tag = vstoWorksheet.Controls.AddControl(button,selection, "Click"); 

應該是:

vstoWorksheet.Controls.AddControl(button,selection, "Click");