Search code examples
pythonvisiopywin32win32com

Cannot open Visio document with Python


I am attempting to do some automation in Visio using Python. I am able to open the Visio application and create a new document, but cannot open an existing document. Here is the code that I am trying.

  import win32com.client

  visio = win32com.client.Dispatch("Visio.Application")  # this works
  doc = visio.Documents.Open("C:\Users\username\test.vsd") # nope

The error I get back is

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<COMObject <unknown>>", line 3, in OpenEx
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Visio', u'\n\nFile not found.', None, 0, -2032465466), None)

I have tried using visio.Documents.OpenEx as well and get the same answer. Any thoughts?


Solution

  • I am guessing that this might work -

    doc = visio.Documents.Open("C:\\Users\\username\\test.vsd")