Search code examples
pythonwindowscomms-project

How to view what functions a COM object has?


I don't quite understand what Component Object Models are. So far I know this opens MS Project in Python 3.x:

import win32com.client

project = 'SomePath\foo.mpp'
mpp = win32com.client.Dispatch("MSProject.Application")

After this, where can I find what are its functions, like opening a file, reading its contents, searching tasks, etc? I tried something like this:

print([method_name for method_name in dir(mpp) if callable(getattr(mpp, method_name))])

or

for item in dir(mpp):
    print(item)

but these doesn't show me all methods of the application.

I couldn't find any info about it anywhere online, can somebody please tell how can I figure its callable functions out?


Solution

  • Well, with a tool like OleView which comes with the Windows SDK, you can view type libraries.

    For the exact object you have, I could figure it out with PowerShell and don't need to use OleView:

    $obj = new-object -com "MSProject.Application"
    $obj | Get-Member
    

    Do that and it will list the methods for MSProject.Application ... because MSProject.Application is a coclass ProgId. It won't work in Python. If you have another object that you can navigate to in PowerShell, you can do the same thing with Get-Member

    Also, if you have Office, you can open a macro window in Excel (or Word or ...), add a reference to MS Project type library, and then use the object browser in the Excel macro window to view the properties and methods of the various objects in MS Project type library.