AnsweredAssumed Answered

For each variable control in arrays - data type variant required?

Question asked by Steven Soeder on Apr 11, 2014

I'm not sure why I'm getting this message.

Compile error:


For Each control variable on arrays must be Variant


I am tyring to iterate through all the open documents

I have a sub routine that I am using to loop through all the open documents and perform an action on them.

My array type is SldWorks.ModelDoc2.

I set my control variable to the same type, and I get that message.

If I change my contorl variable to type "Variant" the code works just fine.



Can anyone explain why the variant type is required?  Is this specific to the SW API?

I've worked in VBA for excel/outlook pretty extensively with arrays. It has been awhile, but I dont recall ever being force to use the Variant type with arrays.

I was always told it was bad to use the Variant type if you know the object type, e.g. unless you can't foresee the object type (passed from some other program, etc.) you shouldn't use the Variant data type.  


Any explanation or steer in the right direction is appreciated.