Reputation:
What this kind of error?
Traceback error
C:\Users\DELL\PycharmProjects\MyNew\venv\Scripts\python.exe
C:/Users/DELL/PycharmProjects/MyNew/agaaaaain.py
Traceback (most recent call last):
File "C:\Users\DELL\PycharmProjects\MyNew\venv\lib\site-
packages\win32com\client\gencache.py", line 530, in EnsureDispatch
ti = disp._oleobj_.GetTypeInfo()
pywintypes.com_error: (-2147418111, 'Call was rejected by callee.', None,
None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/DELL/PycharmProjects/MyNew/agaaaaain.py", line 3, in
<module>
excel = win32.gencache.EnsureDispatch('Excel.Application')
File "C:\Users\DELL\PycharmProjects\MyNew\venv\lib\site-
packages\win32com\client\gencache.py", line 541, in EnsureDispatch
raise TypeError("This COM object can not automate the makepy process -
please run makepy manually for this object")
TypeError: This COM object can not automate the makepy process - please run
makepy manually for this object
Process finished with exit code 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/DELL/PycharmProjects/MyNew/agaaaaain.py", line 3, in
<module>
excel = win32.gencache.EnsureDispatch('Excel.Application')
File "C:\Users\DELL\PycharmProjects\MyNew\venv\lib\site-
packages\win32com\client\gencache.py", line 541, in EnsureDispatch
raise TypeError("This COM object can not automate the makepy process -
please run makepy manually for this object")
TypeError: This COM object can not automate the makepy process - please run
makepy manually for this object
and this is my code
import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
PyCharm
VirtualEnv
I didn't find any solution, any one have idea about this?
Note:How ever I am trying to use win32 to access excel
work book, as to able for modifying it!!..
Upvotes: 9
Views: 25411
Reputation: 21
in case of someone running
excel = win32.gencache.EnsureDispatch('Excel.Application')
with this mistake,
you should check if excel has any notifications, you need to close them and code will run. Can't find any notifications - try to shut down excel.
Upvotes: 1
Reputation: 933
In my case, I was using events over different threads and I forgot setting the coinit_flags
to zero, for example:
# ...
import sys
sys.coinit_flags = 0 # pythoncom.COINIT_MULTITHREADED == 0
from win32com.client import *
from win32com.client.connect import *
# ...
Upvotes: 0
Reputation: 3
Issue also can arise if running the line excel = win32.gencache.EnsureDispatch('Excel.Application')
more then once in your instance (AKA. a For
loop).
Upvotes: 0
Reputation: 2948
I had the same problem...was fixed in my case by adding those 2 lines:
workbook.Close(SaveChanges=True)
xl.Quit()
Upvotes: 0
Reputation: 171
Encountered the same issue and resolve it by closing all running Excel applications.
Upvotes: 17
Reputation: 12
You must consider running the code from a Virtual Environment.
And uninstall any other pywin32 module outside the Environment.
Give it a shot!
Upvotes: -2