c# excel create a button on excel worksheet -



c# excel create a button on excel worksheet -

i trying add together button on excel worksheet. according illustration internet, trying next code.

using excel = microsoft.office.interop.excel; using vbide = microsoft.vbe.interop; private static void exceladdbuttonwithvba() { excel.application xlapp = new excel.application(); excel.workbook xlbook = xlapp.workbooks.open(@"path_to_excel_file"); excel.worksheet wrksheet = xlbook.worksheets[1]; excel.range range; seek { //set range insert cell range = wrksheet.get_range("a1:a1"); //insert dropdown cell excel.buttons xlbuttons = wrksheet.buttons(); excel.button xlbutton = xlbuttons.add((double)range.left, (double)range.top, (double)range.width, (double)range.height); //set name of new button xlbutton.name = "btndosomething"; xlbutton.text = "click me!"; xlbutton.onaction = "btndosomething_click"; buttonmacro(xlbutton.name, xlapp, xlbook, wrksheet); } grab (exception ex) { debug.writeline(ex.message); } xlapp.visible = true;

}

but keeps saying excel not contain button reference should include utilize button property

thanks in advance.

as far can tell, excel.button , excel.button not exist. instead suggested right reference microsoft.office.tools.excel.controls.button (not microsoft.office.interop.excel using). illustration source below

excel.application xlapp = new excel.application(); excel.workbook xlbook = xlapp.workbooks.open(@"path_to_excel_file"); excel.worksheet worksheet = xlbook.worksheets[1]; excel.range selection = globals.thisaddin.application.selection excel.range; if (selection != null) { microsoft.office.tools.excel.controls.button button = new microsoft.office.tools.excel.controls.button(); worksheet.controls.addcontrol(button, selection, "button"); }

source: adding controls worksheet @ run time in application-level project http://msdn.microsoft.com/en-us/library/cc442817.aspx

c# excel

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -