Public Sub DoSomething()
DoSomethingElse "42?"
End Sub
Private Sub DoSomethingElse(foo As Date)
' Debug.Print MonthName(Month(foo))
End Sub
VBA is trying really hard to convert the "42?"
argument into a Date
value. When it fails, the call to DoSomethingElse
cannot be executed, because VBA doesn't know what date to pass, so it raises run-time error 13 type mismatch, because the type of the argument doesn't match the expected type (and can't be implicitly converted either).
Public Sub DoSomething()
DoSomethingElse Now
End Sub
Private Sub DoSomethingElse(foo As Date)
' Debug.Print MonthName(Month(foo))
End Sub
By passing a Date
argument to a procedure that expects a Date
parameter, the call can succeed.