Excel VBA pass object ByRef never sems to work
<p>I've been using VBA for many years but in all that time I've never managed to pass a workbook or sheet ByRef, I've had to use string names &amp; set the objects in the partner sub or function... so finally it's time to get some help!</p>

<pre><code>Sub SubOne()

Dim wb as workbook
Dim filepath as string

filepath = "//somepath/somebook.xlsx"

Set wb = application.workbooks.open(filepath)

Call SubTwo(wb)

End Sub



Sub SubTwo(ByRef wb as workbook)

debug.print wb.name

End Sub
</code></pre>

<p>Can anyone see why this would trigger a ByRef type mismatch compile error? What am I missing?</p>

<p>Many thanks</p>