Problem distinguishing between interfaces (Excel vb.net)

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

Only registered users are allowed to subscribe.
Problem distinguishing between interfaces (Excel vb.net)
sheets vs worksheets vs charts 
Tom Mulholland




Posts: 15
Joined: 2012-06-26
Hi Andrei

Following up on a previous post, it appears that although the Excel object model provides us with access to three sheets collections:

(1) .worksheets
(2) .charts and
(3) .sheets (which is both .worksheets and .charts)

ADX interface offers three interfaces, but only one works (the Sheets one) ?
Using the ADX Worksheets and Charts interfaces both cause my project to close down unexpected, not even throwing an exception!

So to interact with worksheets or charts we first have to grab each sheet via ADX Sheets interface, and then do a TypeOf check first before we can then cast the Sheet as either type Worksheet or type Chart, is that right?

If so (and I'm missing something really obvious in which case apologies!) it would be great if this could be fixed in the next update? Would make coding much more elegant!

Cheers

Tom
Posted 02 May, 2021 10:52:34 Top
Andrei Smolin


Add-in Express team


Posts: 17740
Joined: 2006-05-11
Hello Tom,

Tom Mulholland writes:
cause my project to close down


That means you have an exception that wasn't handled by your code! You should handle such an exception because Office may disable your add-in as faulty.

Workbook.Worksheets property returns a *Sheets* collection (not Worksheets collection) that contains objects of the Sheet type; each of them is essentially a worksheet. When working with that collection, you can cast every Sheet object to Worksheet object without checking if the type is Worksheet.

Workbook.Charts collection works in the very same fashion.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 04 May, 2021 03:53:46 Top
Tom Mulholland




Posts: 15
Joined: 2012-06-26
Thanks - having come from VBA background I was unaware that Excel sees both chart sheets and standard worksheets within the same worksheets collection. Not having to cast type in VBA makes life easier. Appreciate the clarification!
Posted 04 May, 2021 16:51:58 Top
Andrei Smolin


Add-in Express team


Posts: 17740
Joined: 2006-05-11
Hello Tom,

Yes, VBA is easier in some aspects: it hides many things from the developer; you must do these things explicitly in .NET.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 05 May, 2021 01:45:48 Top