4
votes

I'm using python and excel with office 2010 and have no problems there. I used python's makepy module in order to bind to the txcel com objects.

However, on a different computer I've installed office 2013 and when I launched makepy no excel option was listed (as opposed to office 2010 where 'Microsoft Excel 14.0 Object Library' is listed by makepy).

I've searched for 'Microsoft Excel 15.0 Object Library' in the registry and it is there. I tried to use : makepy -d 'Microsoft Excel 15.0 Object Library' but that didn't work.

Help will be much appreciated. Thanks.

3

3 Answers

6
votes

The problem is that the win32com module only looks under the win32 key for Typelib registry entries but Office 15.0 has some win64 keys instead. To work around the problem, locate the part of Lib/site-packages/win32com/client/selecttlb.py that looks like this:

# Only care about "{lcid}\win32" key - jump straight there.
try:
    key4 = win32api.RegOpenKey(key3, "%s\\win32" % (lcid,))
except win32api.error:
    continue

and modify it like so:

# Only care about "{lcid}\win32" key - jump straight there.
try:
    key4 = win32api.RegOpenKey(key3, "%s\\win32" % (lcid,))
except win32api.error:
    try:
        key4 = win32api.RegOpenKey(key3, "%s\\win64" % (lcid,))
    except win32api.error:
        continue

Old question but I hope this helps someone.

1
votes

Here i copy paste from my win32com and office 2015 interaction from pythonwin console:

PythonWin 3.3.1 (v3.3.1:d9893d13c628, Apr  6 2013, 20:30:21) [MSC v.1600 64 bit (AMD64)]  on win32.
Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information.
>>> 
>>> 
>>> from win32com.client import gencache
>>> gencache.EnsureModule('{00020813-0000-0000-C000-000000000046}', 0, 1, 8)
Loading reg typelib {00020813-0000-0000-C000-000000000046} 1 8 0
Rebuilding:  1 8
<module 'win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x8' from 'C:\\Python33\\lib\\site-packages\\win32com\\gen_py\\00020813-0000-0000-C000-000000000046x0x1x8.py'>
>>> import win32com.client as client
>>> client.Dispatch("Excel.Application")
<win32com.gen_py.Microsoft Excel 15.0 Object Library._Application instance at 0x75090800>

As u can see its working perfectly.

I have enabled all the print statements in the gencache module for reference.

Thanks !

0
votes

wilywampa's answer corrects the problem. However, the combrowse.py at win32com\client\combrowse.py can also be used to get the IID (Interface Identifier) from the registered type libraries folder and subsequently integrate it with code as suggested by @cool_n_curious. But as stated before, wilywampa's answer does correct the problem and you can just use the makepy.py utility as usual.