none
Rendering Windows control or WPF control on excel using VSTO 4 destroys class module object RRS feed

  • Question

  • Hi,

    I have created a VSTO addin which renders some windows as well as WPF control on excel worksheet and in the target workbook there is some vba code written which instantiate a class module object as a global object.

    Now as soon as the controls are rendered on the screen. all the class module object destroys.

    After some research i found that excel goes into design mode to render these controls and in design mode the object model becomes null.

    Is there any solution to this problem? How can i suppress excel going into design mode while rendering these controls.

    Thursday, November 24, 2011 11:05 AM

All replies

  • Hi Jinesh

    you can't change this very basic functionality of how Office apps handle initialization of ActiveX controls. Incorporating such controls involves doing things to the "macro storage" (the part of the document structure that works with code). For that, the document must go into Design mode.

    Since this is an Add-in, it means that placing these controls on the document surface is something triggered by your code. So you'd at least have some kind of control about the how/when things happen. You'll need to build something into your code that can somehow save/serialize these class objects before they're destroyed. Possibly, you could mirror this class in your project and "copy" the existing class object to it, then copy them back into the workbook. Something like that is going to be your only way around it.


    Cindy Meister, VSTO/Word MVP
    Friday, November 25, 2011 10:28 AM
    Moderator
  • Hi Cindy,

    Thanks for the response.

    But everything is working fine when i have only one control to render on excel. In that case, even class object values persists.

    The problem occurs only when there are more than one control renders on the sheet. Or

    There are more than one operations on the sheet. Like if i render only one windows control and then i set visibility of one of the existing shape on the sheet to false. This also causes class object to destroy.

     

    Could you please explain this behavior.

     

    Thanks & Regards,

    Jinesh Parmar


    Thanks & Regards, Jinesh Parmar
    Tuesday, November 29, 2011 7:22 AM
  • Hi Jinesh

    I think you need to go into more detail about what you mean by "rendering" controls. Describe more exactly what your solution is and how it functions. Maybe show us some code involved with the "rendering". And specify the version of Excel involved.


    Cindy Meister, VSTO/Word MVP
    Tuesday, November 29, 2011 8:32 AM
    Moderator