everyone!
I have been using the win32com.client module in Python to access cells of an Excel file containing VBA Macros.
A statement in the code xl = win32com.client.gencache.EnsureDispatch("Excel.Application")
has been throwing an error:
AttributeError: module 'win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x6' has no attribute 'MinorVersion'
Has anyone faced a similar situation and, if yes, what can a possible remedy for this? (I've had a look at the source code for win32com on GitHub, but haven't been able to make much sense from it.)
The main reason for this attribute error is because your COM-server has shifted from late-binding (dynamic) to early binding (static).
There are two ways to fix this issue:
Use the dynamic module to force your code to work in a late-bound oriented way. Example use:
"win32com.client.dynamic.Dispatch()" instead of "win32com.client.Dispatch()"
Use camelcase sensitive keywords for the early bound oriented way. Example use:
"excel.Visible()" instead of "excel.VISIBLE()" or "excel.visible()"
Try out
"win32com.client.dynamic.Dispatch()" instead of "win32com.client.gencache.EnsureDispatch"
As win32com.client.gencache.EnsureDispatch forces the MakePy process.