Question

I'm working on converting an old VBA project into a C# VSTO. I know a lot of the code has to go out of the window, but I was hoping to still use the layout and objects that had been embeded into the sheet. Examples of the objects include controlbuttons, labels, images, etc.

All of these persist nicely when I choose the document as a template when making a new project. I run into the problem in that I can't seem to select or reference any of these objects. For example there's a button in the middle of a sheet. If I open the sheet in VS2012, I can see the button. I can even "highlight" it but not select it. If I right-click on the button to pull up the properties, it will bring up the properties for the sheet, not the button. I can't resize them or move them around (not that I want to).

I also can't seem to reference them in code, ie ...Sheet1.ControlButton1... or ...Sheet1.OleObject(n)... will never refer to anything. If I open up the workbook directly from the solution folder and click on the same control I can see properties, and the formula bar in Excel reads =EMBED("Forms.CommandButton.1","").

I've also not been able to loop through all the OleObjects and just display their names. Clearly where ever the collection is that is storing these I can't find it.

Was it helpful?

Solution

Try the Workbook.Shapes collection

Edited as per the comments below. This works: Globals.ThisWorkbook.Worksheets(1).OLEObjects("CommandButton1");

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top