2

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?

Chris
  • 619
  • 2
  • 9
  • 18

2 Answers2

5

I am guessing that this might work -

doc = visio.Documents.Open("C:\\Users\\username\\test.vsd")
hyades
  • 3,110
  • 1
  • 17
  • 36
0

Instead of forward slashes you can use backward ones

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

or

doc = visio.Documents.Open("C:/Users/username/test.vsd")
Puneet Sinha
  • 1,041
  • 1
  • 10
  • 23