How to insert a control built with Interop Forms Toolkit in Excel
-
vendredi 25 juin 2010 08:24
Hi,
I created a control with the Interop Forms Toolkit and I can insert the control in a worksheet by these 2 ways:
- The developper toolbar insert an activex control
- With a macro
Now, I want to insert the control, but from an addin CommandBarButton built with VSTO.
It throws an exception with code 0x800A03EC and a message saying unable to insert an object.
Technical informations : I'm using VSTO 2005 SE with VS2005 .Net Framework 2.0 for the addin. The control is built using Interop Forms Toolkit 2.1 in VS2008 .Net Framework 2.0.
I tried the same code to insert my control and a label. The label works, my control doesn't:void buttonAddin2_Click(...) { try{ Excel.Worksheet sheet = (Excel.Worksheet)Application.ActiveWorkbook.ActiveSheet; sheet.Shapes.AddOLEObject("Forms.Label.1", missing, false, false, missing, missing, missing, 50,50,100,100); } catch (Exception exc) { MessageBox.Shox(exc.ToString()); } }I think I'm missing something, but the error message is not very helpful.
Why it is possible to add my control in Excel via "standard" ways, but not via my addin ? How can I make my addin able to insert my control ? Do I have to update the control ? Is there something to change in the addin to allow it to insert my control ?
And if there is no answer about it, is there any way to get more details about the errors ?Many thanks,
Julien
Toutes les réponses
-
mardi 29 juin 2010 09:47
Hi,
I've tried another approaches
- I tried to create a macro at runtime, then execute it to insert my control. It doesn't work...
- The addin is an Excel Addin based on VSTO template. So I tried another approach: building an addin based on Extensibility.IDTExtensibility2 interface (a COM Addin) instead of the other one. Now it works ! I've used exactly the same code... it works using the AddOLEObject or executing the macro...
Does anybody have an explanation of this behaviour?
I'm new in extending Office applications and I don't understand why it works when I create a COM Addin based on Extensibility.IDTExtensibility2, and it doesn't using the Excel addin template coming with VSTO ?What are the key differences between these 2 kind of extensions ?
Thanks,
Julien

