Python accessing win32com.client.constants

After installing the relevent installation of pywin32 you will be able to start accessing win32com items.

I will show you an example for accessing Outlook from Python.

According to Microsofts documentation here after you've set a variable with the NameSpace object, if you want to get the default folder in outlook for certain things like Inbox, Trash, Sent, Deleted...etc. What you do is call .GetDefaultFolder(olFolderInbox) and that will return the default Inbox folder in the Outlook you are connecting to.

Python doesn't know what olFolderInbox is by default, it's just another variable that is undefined yet. win32com gives you access to these constants by going to win32com.client.constants.WhatEverYouNeed. By default though win32com does not make these constants, you need to run another application.

  1. Search your Start Menu in Windows for Pythonwin OR look for C:\Python34\Lib\site-packages\pythonwin\Pythonwin.exe replacing Python34 for which ever version you are using.
  2. Go to Tools
  3. Select COM Makepy Utility
  4. Depending on which application you wish to access, in my case I wanted Outlook, Excel, and Word, you need to look for Microsoft Outlook XX.X Object Library (X.X) Word and Excel look similar. You can either repeat steps 2, 3, and 4 for each one individually or just use CTRL and select all 3 at once.
  5. Select OK
  6. In the Interactive Window you will see the following lines
    1. Building definitions from type library...
    2. Generation...
    3. Importing module
  7. Once you see Import module hit enter and then close PythonWin application.

You will now be able to access win32com.client.constants.olFolderInbox