0

Why do I get a type mismatch running sub bar below in Excel VBA?

Sub foo(c As Collection)
    Debug.Print c.Count
End Sub

Sub bar()
    Call foo(Worksheets)
End Sub

The code above is a minimal working example intended to focus only on the Type related issues. The origin of this question is that, at some point, the code from This existence test for a member of a collection worked, but now I get the same type mismatch described in this question.

I wonder what detail is causing the type confusion. Is Worksheets not a Collection?

Community
  • 1
  • 1
Leo
  • 2,775
  • 27
  • 29
  • 1
    If you're running that in Excel VBA then why is this question tagged with VB.NET but not VBA? – jmcilhinney Mar 03 '17 at 04:57
  • Oddly enough, I checked the tags before posting. They were `excel`, `vba`, and `excel-vba`. I fixed them back to those values. Thanks for the heads up. – Leo Mar 03 '17 at 05:21
  • instead of declaring c as collection, try declaring it as a variant – Sivaprasath Vadivel Mar 03 '17 at 05:40
  • But if you declare as `Variant` you can't use the methods from Collection. Isn't `Worksheets` a `Collection`? – Leo Mar 03 '17 at 10:06

0 Answers0