[python-win32] type mismatch using win32com.client.GetObject

Tim Roberts timr at probo.com
Fri Sep 28 21:01:49 CEST 2007

David wrote:
> So I have a Visual Basic script in Excel which connects via com to
> programX and retrieves data. The COM function takes 7 required
> arguments. arg1-6 are set equal to values to determine what data to
> fetch. arg7 is the variant in which the function returns the fetched
> data.
> ...
> The end of which the variable 'data' is set to the value returned by
> the com interface.
> So when I call the function, I get:
> arg1 = ...
> setting all arg# variables
> ...
> x1 = functionX(arg1, arg2, arg3, arg4, arg5, arg6)
> and x1 = the returned value
> When I try this in python, I get a type mismatch, for the apparent
> reason that arg7 is not a variant. Of course, python being the
> wonderful language it is, arg7 can be any type I want, whenever I want
> to change it.... except there is no 'variant' type because of this.
> >>> arg1 = ....
> setting all arg# variables
> ...
> >>> x1 = win32com.client.GetObject("programX.activex.interface ")
> >>> `x1`
> '<COMObject programX.activex.interface>'
> >>> x1.FunctionX(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9,
> arg10)
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in <module>
>   File "<COMObject programX.activex.interface >", line 2, in FunctionX
> com_error: (-2147352571, 'Type mismatch.', None, 7)
> >>>
> So I'm at a loss as to how to force passing arg7 as a variant type.
> From what I gather in researching this, win32com.client is supposed to
> handle typing automagically. Somehow I'm missing something.

If arg7 is the output argument, then you probably want:

   arg7 = x1.FunctionX(arg1, arg2, arg3, arg4, arg5, arg6, arg8, arg9,

I'm not sure if it will handle functions where the output argument is
not the final argument.

Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

More information about the python-win32 mailing list