コード例 #1
0
        public static void ExcelAddButtonWithVba(Excel.Application app, Excel.Workbook workbook, Excel.Worksheet worksheet)
        {
            Excel.Range range;

            try
            {
                //set range for insert cell
                range = worksheet.get_Range("J1");

                //insert the dropdown into the cell
                Excel.Buttons xlButtons = (Excel.Buttons)worksheet.Buttons();
                Excel.Button  xlButton  = xlButtons.Add((double)range.Left, (double)range.Top, (double)range.Width, (double)range.Height);

                //set the name of the new button
                xlButton.Name     = "btnDoSomething";
                xlButton.Text     = "Insert";
                xlButton.OnAction = "A87A";

                app.UserControl = false;
                app.Visible     = false;

                ButtonMacro(xlButton.Name, workbook);
            }
            catch (Exception)
            {
            }

            app.Visible = false;
            //app.DisplayAlerts = false;
        }