Excel VB Code for .vdx needs converted to read 2013 .vsdm

Started by DJHarris71, January 17, 2014, 04:57:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DJHarris71

Hello,

I have a large excel vb project (10 years old) that searches for data in the .vdx file, updates the data, and saves the file as a .vdx.

Visio 2013 has broken this code. It appears the tree structure is similar from what I have read, but the xml is different.  I need help on how to modify the code.  Below is the old code that read the file.  I am hoping this is the core of what I need to change.  Once I can see the tree in excel, It will be easy to adjust anything else (I hope).

            ' Load XML File into Memory
            Set docXML = New DOMDocument40
            docXML.Load Sim(1).SimFileName  'this is the file name saved in an object
            docXML.async = False
            docXML.setProperty "SelectionLanguage", "XPath"
            docXML.setProperty "SelectionNamespaces", "xmlns:vx='http://schemas.microsoft.com/visio/2003/core'"

You can see that this is usung the XML4.0 extension. I am sure that will need to change too.

Any tips?  and Thanks in advance.

nashwaan

Probably if you could save the .vsdm as .vdx, then this will solve your problem. The strange thing: it is not clear to me how to save a Visio drawing as .vdx file in Visio 2013. Although Visio 2013 can open .vdx files!

On the other side, the XML schema for Visio 2013 has been changed from the 2003 version. But I suspect most of Visio 2013 XML is still readable by 2003 Document Object.

From my understanding:
.vdx is itself an xml file.
.vsdx/.vsdm is a zip file that contains many files and folders among which are some XML files (try to rename your .vsdm file to .zip and you will see its contents). Therefore, if you still want your old code to work (not guaranteed), you need to extract the right XML file from the .vsdm file. (you can check this article by Ron de Bruin to start with).

I think John Goldsmith, a Visio MVP, has a better answer to your problem. Hope he will notice your post.

Regards,
Yousuf.
Give me six hours to chop down a tree and I will spend the first four sharpening the axe — Abraham Lincoln

DJHarris71

#2
Yousuf, thanks for the reply.

A few things I have found based off your comments.

I wanted to validate that the file does in fact open properly, and sure enough the code does not fail on opening the file via the docxml.load line as it does seem to open an xml file.  However I was looking at the structure and I do not see any children nodes.

I opened up the .vsdm file and indeed, I do see that page 1 is an .xml file within the .vsdm.

At this point, I am wondering how to deal with this. I am thinking of doing this: change the file to .zip, navigate to the folder, open the .xml file, edit, save, and change the file name back to .vsdm.

Thanks for the tips.  More thoughts and feedback appreaciated, and I do also hope John Goldsmith happens to see this.

Doug

DJHarris71

I think I found the answer in an excel forum.  this looks crazy!  Its as I thought but more complex: unzip, read, edit, write, rezip.
http://msdn.microsoft.com/en-us/library/dd819387(v=office.12).aspx

JohnGoldsmith

Hello Doug,

It's kind of Yousuf to recommend my blog, but really Al Edlund is the expert on the 'new' file format.

As you've discovered Visio 2013 has adopted the packaging conventions (zipped file format) that other Office applications have had for a while now.  The older .vdx format was a single xml based text file where the new vsdx (and similar) format represents a zipped package that can be unpacked to reveal a set of text (mostly xml) and binary files in addition to a further set of xml files that describe the relationships between the package components.

In general I think this a good thing, but it does mean that you have some work ahead modifying your existing code to the new format.  A lot of the vdx structure still exists albeit separated into individual parts.  2013 makes much better use of inheritance and so you may find yourself scanning up and down the hierarchy to get a full picture of a given shape.  However if you're just after editing the Shape Data, this maybe an easier task (as opposed to reading the entire document).

I don't have any experience of using packaging from VBA specifically (although the Excel link you referenced looks interesting), but if you have a choice then I would seriously consider .NET as I suspect you'll find this easier.

In terms of discovering more about the new file format, here are a few links that might help:

Hope that helps.

Best regards

John
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

nashwaan

I am glad that John has replied to your post and for his insightful comments.

It looks like both options are not trivial whether to manipulate the .vsdm file or going with .NET approach (specially if you don't have experience).

I suggest, in order to save time and avoiding learning the differences between old and new Visio XMLs, to do the following:

  • Using Visio 2013, save the .vsdm file as .vsd file
  • Using Visio 2010/2007/2003, save the .vsd file as .vdx file
  • Run your existing code to manipulate the .vdx file as you use to do.

Regards,
Yousuf.
Give me six hours to chop down a tree and I will spend the first four sharpening the axe — Abraham Lincoln

Simulation_Guy

Does anyone know if anyone has written a macro or add-in that would allow us to "save" a current visio drawing as a .vdx file from within Visio 2013?


Simulation_Guy

Thanks for the suggestion Jumpy. I tried running the "saveAs" function with the .vdx extension... this correctly names the file, but it is not actually creating a .vdx file, I think its just creating a .vsdx file and renaming it.

Microsoft has clearly stated that they no longer support this old .vdx format, I was just hoping that someone had written some code to emulate the old SaveAs behaviour that they would be willing to share.

aledlund

v2013 does not create vdx files because the native format is already XML.
al
the primary reason your existing app will have issues is the xml schema is different between the two implementations.