Python Pywin & OneNote COM: OneNote.Application.15 'cannot automate the makepy process'

com, onenote, python, winapi

Solution

Check your registry record, in particular key {0EA692EE-BB50-4E3C-AEF0-356D91732725} in TypeLib section:

HKEY_CLASSES_ROOT\TypeLib\{0EA692EE-BB50-4E3C-AEF0-356D91732725}

This strange bevahior is probably caused by existence of invalid subkeys. This class key have to contain only a single subkey "1.1" and nothing else.

The correct registry record for this class should look as follows:

|- {0EA692EE-BB50-4E3C-AEF0-356D91732725}
|     |- 1.1
|         |-0
|         | |- win32
|         |- FLAGDS
|         |- HELPDIR

The key "win32" have to point to OneNote executable, e.g. C:\PROGRA~1\MICROS~1\Office15\ONENOTE.EXE\3

Problem

I'm interacting with OneNote's COM interop using Python on Win32. Here's the most basic code to pull out notebook hierarchy: ``` import win32com.client onObj = win32com.client.gencache.EnsureDispatch('OneNote.Application.12') result = onObj.GetHierarchy("",win32com.client.constants.hsNotebooks) print(result) ``` Note the `OneNote.Application.12`, this works as I'd expect. The thing is that when I run Makepy I'm actually selecting the v15 type library: If I change the code to be either `OneNote.Application.15` or just `OneNote.Application` then I get an error: ``` TypeError: This COM object can not automate the makepy process - please run makepy manually for this object ``` Why is this please? I'm running: - Python 3.3.1 (64bit) - Pywin build 218 (AMD64) - Win 8 x64 - Office 2013 x64

Original source