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

StackOverflow https://stackoverflow.com/questions/16287432

  •  13-04-2022
  •  | 
  •  

문제

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:

enter image description here

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
도움이 되었습니까?

해결책

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

다른 팁

In site-packages\win32com\ there was a folder F2A7EE29-8BF6-4A6D-83F1-098E366C709Cx0x1x0, this contained the v12 type library. There was also a file 0EA692EE-BB50-4E3C-AEF0-356D91732725x0x1x1.py which looks like the v15 lib.

Changing my code to:

gencache.EnsureModule('{0EA692EE-BB50-4E3C-AEF0-356D91732725}', 0, 1, 1)
onapp = win32com.client.Dispatch('OneNote.Application.15')

I get access to the v15 type library. I'm still not clear why it requires this explicit reference, though.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top