C
ColinBurrows
Guest
Ive been using an Excel VBA custom function for years that Ive come to rely on. Its a Boolean function named IsInCollection and consists of just the following 3 lines:
On Error Resume Next
Set obj = collectionObject(itemObject)
IsInCollection = Not (obj is Nothing)
It can be used anywhere you need to know if a collection contains a given item and, because the two arguments are defined as objects, it works regardless of whether its a collection of workbooks, worksheets, range names, pivot fields, etc. Im trying to set up the same thing in managed code (C#), but cant figure out how to iterate thru the collection object, or cast it so that .NET sees it as enumerable. The collectionObject seems to be of type System._ComObject so Ive been trying to read up on QueryInterface but to no avail.
If anybody has any tips or can point me in the right direction then it would be much appreciated.
TIA
Continue reading...
On Error Resume Next
Set obj = collectionObject(itemObject)
IsInCollection = Not (obj is Nothing)
It can be used anywhere you need to know if a collection contains a given item and, because the two arguments are defined as objects, it works regardless of whether its a collection of workbooks, worksheets, range names, pivot fields, etc. Im trying to set up the same thing in managed code (C#), but cant figure out how to iterate thru the collection object, or cast it so that .NET sees it as enumerable. The collectionObject seems to be of type System._ComObject so Ive been trying to read up on QueryInterface but to no avail.
If anybody has any tips or can point me in the right direction then it would be much appreciated.
TIA
Continue reading...