Excel - adding control programmatically.

  • Thread starter Thread starter Alan B
  • Start date Start date
A

Alan B

I have a COM+ control written in C++ that I wand to use in an Excel sheet.
I can drop one into the sheet visually no problem ,add a button and talk
to my control just fine.

Then I tried to create an instance of the control programmatically
instead, inside the click code of a button. I don't want to actually add
it to the sheet, I just want to create it, query it and stick the results
in a cell. I can't get this to work. The nearest I can get is using the
OLEObjects collection of the workbook, but adding it into there actually
adds it to the sheet. Is this just the way Excel has to work, i.e.
anything you create from a control has to be contained in a sheet to work
??
 
Alan,

there are several simple ways around:
1) create a hidden sheet and manipulate you control there. User won't see
anything, and on exit you can delete the sheet.

2) you can turn off screen updating, create control/use it/delete, and then
turn on screen again., User won't see a thing again.

3) you can put control on the sheet, but set your control's Visible property
to false, and it will exist only in the memory

4) finally, I think (I might be wrong) that Excel needs your control to
belong to an object, like a worksheet or a user form. As I said, you can
create a dummy sheet or an invisible user form (just initialize it and hide,
unload on exit).

Hope it helps -

RADO
 
What you actually have to do is create a reference to it. Then you don't
have to add it to the sheet at aall. Thx anyway.
 
Back
Top