Save VSD as VDX

A

Anton

I'm trying to save .vsd files as Visio XML via visual basic.

I have this:
ActiveDocument.SaveAs location & name & ".vdx", where location is e.g.
"C:\" and name is e.g. "test.vsd".

Apparently that doesn't work because the file structures of vsd and
vdx are different, I guess. Anyway, I tried it this way but I got a
file named "test.vsd.vdx.vsd".

Am I using a wrong method or have I just overlooked something? Any
help would be more than welcome.
 
J

John Goldsmith

Hello Anton,

What you're doing with the ampersand character is concatenating a string
into a final (and full) file path. The file extension for an XML Visio file
is .vdx so you need to ensure that that's at the end of your final string.

So here's a few examples all with the same result, (based on your
variables):

Sub SaveMyFileAsXML()
'Produces a file with a full path of:
'C:\Documents and Settings\MyUserName\Desktop\MyNewFileName.vdx
Dim location As String
Dim name As String

location = "C:\Documents and Settings\MyUserName\Desktop\"
name = "MyNewFileName"
ActiveDocument.SaveAs location & name & ".vdx"
End Sub

OR

Sub SaveMyFileAsXML()
'Produces a file with a full path of:
'C:\Documents and Settings\MyUserName\Desktop\MyNewFileName.vdx
Dim location As String
Dim name As String

location = "C:\Documents and Settings\MyUserName\Desktop\"
name = "MyNewFileName.vdx"
ActiveDocument.SaveAs location & name
End Sub

OR

Sub SaveMyFileAsXML()
'Produces a file with a full path of:
'C:\Documents and Settings\MyUserName\Desktop\MyNewFileName.vdx
Dim location As String
Dim name As String

location = ""
name = "C:\Documents and Settings\MyUserName\Desktop\MyNewFileName.vdx"
ActiveDocument.SaveAs name
End Sub

They all have the same result.

If you want to save your file in normal (binary) format then just use one of
the above but replace ".vdx" with ".vsd".

Hope that helps.

Best regards

John


John Goldsmith
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk
 
A

Anton

Hello Anton,

What you're doing with the ampersand character is concatenating a string
into a final (and full) file path. The file extension for an XML Visio file
is .vdx so you need to ensure that that's at the end of your final string.

So here's a few examples all with the same result, (based on your
variables):

Sub SaveMyFileAsXML()
'Produces a file with a full path of:
'C:\Documents and Settings\MyUserName\Desktop\MyNewFileName.vdx
Dim location As String
Dim name As String

location = "C:\Documents and Settings\MyUserName\Desktop\"
name = "MyNewFileName"
ActiveDocument.SaveAs location & name & ".vdx"
End Sub

OR

Sub SaveMyFileAsXML()
'Produces a file with a full path of:
'C:\Documents and Settings\MyUserName\Desktop\MyNewFileName.vdx
Dim location As String
Dim name As String

location = "C:\Documents and Settings\MyUserName\Desktop\"
name = "MyNewFileName.vdx"
ActiveDocument.SaveAs location & name
End Sub

OR

Sub SaveMyFileAsXML()
'Produces a file with a full path of:
'C:\Documents and Settings\MyUserName\Desktop\MyNewFileName.vdx
Dim location As String
Dim name As String

location = ""
name = "C:\Documents and Settings\MyUserName\Desktop\MyNewFileName.vdx"
ActiveDocument.SaveAs name
End Sub

They all have the same result.

If you want to save your file in normal (binary) format then just use one of
the above but replace ".vdx" with ".vsd".

Hope that helps.

Best regards

John

John Goldsmithwww.visualSignals.typepad.co.ukwww.visualSignals.co.uk

Thanks for your reply, but it didn't work. A bit more explanation:

I'm using Visio 2007.
Users of Visio 2007 can select in Tools - Options - Save/Open to save
their drawings in vsd or vdx.
I'm trying to process their drawings trough xsl(t) so whatever the
original file is, my temp file has to be in vdx.

I'm pretty sure the problem is caused by the option Save/Open as vsd.

Anyway, your solutions were appreciated but they worked exactly like
mine.

<<some code>>

location_temp = location_visio_files + "xml\"
temp_name = "temp_" & original_name
ActiveDocument.SaveAs location_temp & temp_name & ".vdx"

<<some code>>

location_temp is "C:\bla\bla\bla\"
original_name is "drawing1.vsd" OR drawing1.vdx

Maybe I need to cut of the original file extension?
 
J

John Goldsmith

Hello Anton,

Where is it not working (on what line and what is your error message...are
you getting an error)?

A few thoughts:

1) No, you don't have to cut the orginal .vsd ("MyFile.vsd.vdx" is an xml
format file and the middle .vsd will be ignored)

2) You are doing this from within Visio, right?

3) If your subsequent code is trying to process the xml, are you giving the
save procedure a chance to complete, using something like DoEvents()?

Let me know a few more details on what is not happening and we'll try and
track down the problem (works for me by the way).

Best regards

John


John Goldsmith
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk
 
A

Anton

Hello Anton,

Where is it not working (on what line and what is your error message...are
you getting an error)?

A few thoughts:

1) No, you don't have to cut the orginal .vsd ("MyFile.vsd.vdx" is an xml
format file and the middle .vsd will be ignored)

2) You are doing this from within Visio, right?

3) If your subsequent code is trying to process the xml, are you giving the
save procedure a chance to complete, using something like DoEvents()?

Let me know a few more details on what is not happening and we'll try and
track down the problem (works for me by the way).

Best regards

John

John Goldsmithwww.visualSignals.typepad.co.ukwww.visualSignals.co.uk

I'm getting no errors at all, but when I choose "save as vsd" in tools
- options, my file still gets a vsd extension. Something like
blaat.vsd.xvd.vsd. When I choose "save as vdx", my file looks like
this: blaat.vsd.vdx.

ad. 2) I'm doing this from within Visio, my macro is supposed to save
the original file as vdx, create a temp file vdx, load the original
file and a xsl file and then create a xml file.

ad. 3) He doesn't start the transformation because he can't read and
load a vsd file. So, at that point, I get a error message like: "bla
bla, can't read vsd" which is perfectly normal.

To me, it looks like I can't overrule the option "save as", which
would be strange.

Btw, I really appreciate your help... thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top