I’m trying create new object from a module class in VBA, and I have a small diffcult. Two line of assigning code, look like the same, but result is different.

I got a error message:

After that, I switch to use (1) instead of (2), error was fixed.

But I dont understand; Why do they have this difference?
If you do not use
Dimto declare the specific type of a variable you may subsequently change the variable to another type, for example after;set aosh = new AOSHRatioQueryYou could mutate the variable to a string;
aosh = "A pint of milk"As the
sendAsyncRequestmethod expects aAOSHRatioQueryas its 2nd argument & the VBA compiler knows that it cannot guarantee that theaoshvariable will actually contain an instance of that type, type safety is violated & the Type Mismatch error is raised to preventsendAsyncRequestfrom receiving garbage it cannot interpret.Explicitly typing with
Dim aosh as new AOSHRatioQuerytells the compiler thataoshis guaranteed to always beAOSHRatioQueryinstance orNothing(attempting to assign it to another type will raise an error) so it can be passed safely.