Use VarTypeName() to check the data type of variables on the failing line. The "IDispatch..." error normally means that you are using a complex data type (such as an object or array) where a simple data type (such as a string) is expected.

This can catch you out for example when (say) an AD object property is usually a simple string, but can sometimes be an an array when multiple values are returned.