Answer the question
In order to leave comments, you need to log in
Fix win32com.clien.Dispatch('Outlook.Application') error when Outlook is closed?
Good afternoon, I have a problem with the simplest code for working with COM through win32com.client. The error has been found to only occur when Outlook is closed and runs correctly when Outlook is initially launched.
Given:
Outlook 2019 64-bit
OS Windows 10 x64
Python 3.9
The application is written in the pycharm IDE under the admin account.
Code:
import win32com.client as win32
outlook = win32.Dispatch(“Outlook.Application”)
Error:
Traceback (most recent call last):
File “C:\Python39\lib\site-packages\win32com\client\dynamic.py ”, line 81, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, 'Operation not available', None, None)
How can I solve this problem? How can I handle this error and run the outlook application from python before executing win32.Dispatch(“Outlook.Application”)?
Answer the question
In order to leave comments, you need to log in
This indicates that Outlook is not installed. "windows live" or "outlook.com" won't help you.
I had a similar error. Have you tried running makepy.py from the win32com folder to create entries for the various COMobjects you use? Basically, win32com just treats all applications you interact with as COMobjects by default until you let it know about the programs installed on your computer. You will have to run makepy.py for each program you want to control with it.
After I launched it, I got access to much more control for Outlook. It opened up other bugs that I'm working on fixing.
Also, if you take your comobject ( comboject = win32com.client.Dispatch("Outlook.Application") ) and look at comboject._prop_map_get_.keys() , you will see everything you can use for this program.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question