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?

2
  • error says File not found Commented Sep 23, 2014 at 18:16
  • 1
    can you try doc = visio.Documents.Open(r"C:\Users\username\test.vsd") Commented Sep 23, 2014 at 18:20

2 Answers 2

5

I am guessing that this might work -

doc = visio.Documents.Open("C:\\Users\\username\\test.vsd")
Sign up to request clarification or add additional context in comments.

2 Comments

Nice! Didn't realize I had to escape the backslashes. Thanks a lot!
I thought Visio itself is not installed in the machine... but if it worked then +1
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")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.