Tuesday, January 16, 2007

Fix Visio 2003 VML code for IE7 with Powershell

I have recently been tasked with providing a lot of documentation around the applications that I am working on.  I naturally turned to Visio to help me with my dataflow and physical network diagrams.  I'm using Visio 2003 and have found that this version will export your Visio file and all of its pages as a web site.  By default all of your pages will be converted into VML.  You can also insert hyperlinks into the objects on your diagram that link to other pages.

This produces a really neat web site with built in navigation and search capabilities.  It even works in FireFox, sort of.  FireFox users see a dumbed down version without the search.  I discovered my issue when I tried to use the site in IE7.  Apparently IE7 doesn't like the way the links are built.  I found more information here.  It looks like Office 2007 will fix this. 

There is a short term fix.  You just have to replace the 'href="#"' in all the vml objects to 'style="cursor:pointer;"' for each file that was generated.  In my case, I have over a dozen files.

At the bottom of the article in the comments someone mentions that there is a utility that you can down load and install to perform the fix.  But my machine is still pissed off about the last dinky utility that I installed and only use once in a blue moon.  Powershell can do this, no sweat.  Here's the line that I used.

ls vml_*.htm | % { echo $_.Name; (gc $_.FullName) -replace("href=`"#`"", "style=`"cursor:pointer;`"") | out-File $_.FullName }

First off, I'm getting all the htm files with vml code in them.  Visio conviently labels them as vml.  Then, for each file I write out the name to the console.  You don't have to have this, but I like seeing what files were processed.  The gc command reads the file into a string and the -replace command does the replacing work.  Notice that the escape character in Powershell is "`" not "\".  Finally, the original file is overwritten with the corrected string.

No comments: