win32com.client.gencache.EnsureDispatch error

dieEneLars 1 Reputation point
2021-11-26T11:28:53.3+00:00

Hi Everyone,

I have made a python application that uses the win32com.client library. Basically it opens visio, it imports a stencil, it adds a document and it drops some components on the page. The code looks like this:

#Get visio application
import win32com.client as win32
visio = win32.gencache.EnsureDispatch('Visio.Application')
visio.Visible = True

input("Press enter to continue")

stencilPath = "W:/Systeembeheer/Visio/BigBrother_Stencil.vssx"

document = visio.Documents.Add("")
stencil = visio.Documents.Open(stencilPath)
page = document.Pages.Item(1)

But this no longer works. When I start my program it opens visio, then crashes and throws me this error.

Traceback (most recent call last):
  File "c:\Users\lars\OneDrive - HAN\School LJ 3\Stage\Stageopdrachten\Opdracht interactive netwerktekening\Programma\main.py", line 3, in <module>
    visio = win32.gencache.EnsureDispatch('Visio.Application')
  File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\gencache.py", line 618, in EnsureDispatch
    disp = win32com.client.Dispatch(prog_id)
  File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\__init__.py", line 118, in Dispatch      
    return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx)
  File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\__init__.py", line 46, in __WrapDispatch
    klass = gencache.GetClassForCLSID(resultCLSID)
  File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\gencache.py", line 197, in GetClassForCLSID
    mod = GetModuleForCLSID(clsid)
  File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\gencache.py", line 242, in GetModuleForCLSID
    mod = GetModuleForTypelib(typelibCLSID, lcid, major, minor)
  File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\gencache.py", line 284, in GetModuleForTypelib
    AddModuleToCache(typelibCLSID, lcid, major, minor)
  File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\gencache.py", line 658, in AddModuleToCache
    SetTypelibForAllClsids(mod.CLSIDToClassMap)
AttributeError: module 'win32com.gen_py.00021A98-0000-0000-C000-000000000046x0x4x16' has no attribute 'CLSIDToClassMap'

Can someone help me fix this, because I've tried for 4 hours now and have no result yet.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,033 questions
0 comments No comments
{count} votes