Add a Control Dynamically to a Excel Sheet

Add-in Express™ Support Service
That's what is more important than anything else

Add a Control Dynamically to a Excel Sheet
 
Rafael Castañeda




Posts: 36
Joined: 2010-04-05
Hi I would like to add a control at run time to a excel sheet, I can do it with vsto with the following code

Dim dtpDate as DateTimePicker
dtpDate = Me.Controls.AddDateTimePicker(Me.Range("D3"), "dtpDate")

the problem is that in my adx project I can not access the "Controls" collection.

Thanks in advance

Rafael
Posted 04 Aug, 2010 14:11:21 Top
Eugene Astafiev


Guest


Hi Rafael,

The following code works for me:

      Excel.Worksheet ws = ExcelApp.ActiveSheet as Excel.Worksheet;
            Excel.DropDowns dds = (Excel.DropDowns)ws.GetType().InvokeMember("DropDowns", System.Reflection.BindingFlags.GetProperty |
                 System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Default , null,
                 ws, null, System.Globalization.CultureInfo.CurrentUICulture );
            Excel.DropDown dd = (Excel.DropDown)dds.GetType().InvokeMember("Add", System.Reflection.BindingFlags.Default |
                 System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Instance,
                 null, dds, new object[] { 10, 10, 100, 20, true }, System.Globalization.CultureInfo.CurrentUICulture);
            dd.GetType().InvokeMember("Caption", System.Reflection.BindingFlags.Instance |
                 System.Reflection.BindingFlags.SetProperty | System.Reflection.BindingFlags.Default, null,
                 dd, new object[] { "Eugene Astafiev" }, System.Globalization.CultureInfo.CurrentUICulture);
Posted 05 Aug, 2010 06:30:50 Top
Rafael Castañeda




Posts: 36
Joined: 2010-04-05
thank you Eugene, We will try this
Posted 11 Aug, 2010 11:13:26 Top
Eugene Astafiev


Guest


You are welcome, Rafael :-)
Posted 11 Aug, 2010 11:22:47 Top