Today, I try open Visio document with this simple code
import win32com.client as w32
application = w32.Dispatch("Visio.Application")
application.Visible = True
application.AlertResponse = 0
# application.Documents.Open ('C:\Program Files\Microsoft Office\root\Office16\visio content\1033\dtlnet_m.vstx')
application.Documents.Open ('C:\test\0001.vsd')
Code works fine with build-in templates like 'dtlnet_m.vstx', but cant open any vsd(*)-document at my PC !!!
I try use methods: Open, OpenEx, Add.
Double-quotes, not single-quotes.
application.Documents.Open ("C:\test\0001.vsd")
Quote from: Paul Herber on August 16, 2022, 11:34:37 AM
Double-quotes, not single-quotes.
I try both !
When I copy file path from Windows Explorer, first letter is small.
Met this issue in Jupyther Notebook. Try also Jupyther Lab, VS Code.
About the quotes:
Python accepts single, double and triple quotes equally. The triple ones are for multi line string values (long text).
The important thing is the back slash, it is an escape character.
eg:
\n ist not "\n" but a line return (vbCrLf)
\t is a tab character (chr(9) from memory)
There are different ways to let Python interpret them correctly.
replace them by double back slashes --> application.Documents.Open ('C:\\test\\0001.vsd')
or declare the string as "raw" so as not to interpret any escape character. Write lower "r" in front of the string. --> application.Documents.Open (r'C:\test\0001.vsd') - preferred method since much simpler.
Quote from: Yacine on August 17, 2022, 07:23:36 AMor declare the string as "raw" so as not to interpret any escape character. Write lower "r" in front of the string.
Excellent! Thank you!!!
Quote from: Yacine on August 17, 2022, 07:23:36 AM
replace them by double back slashes --> application.Documents.Open ('C:\\test\\0001.vsd')
I try this trick yesterday with no luck, but today ot works :o
Quote from: Surrogate on August 17, 2022, 07:55:51 AM
I try this trick yesterday with no luck, but today ot works :o
It works only on odd days. :D :D :D
Snake bit.