I have been fooling around with Visio automation since attempting to help a friend with a project that did so. In the course of this I did this code snippet to convert the Visio page to an image. The code loops through and takes each page and converts it to an image. Pretty basic. I have not posted in a while and my apologies to those of you who were wondering….
Here is the code….
Sub SaveAsImage()
‘ creates an invisible Visio instance, opens a document, then
‘ saves all pages in the document as jpg images using
‘ page name and page number as file name
Dim vsoApp As Visio.Application
Dim vsoDoc As Visio.Document
Dim PathName As String, jpgName As String
Dim pg As Visio.Page
Set vsoApp = CreateObject(“Visio.InvisibleApp”)
‘ SET PATH/FILENAME BELOW TO VSD ON YOUR SYSTEM
Set vsoDoc = vsoApp.Documents.Open(“c:\TEST\test.vsd”)
PathName = vsoApp.Documents(1).Path ‘ Set pathname to that of first document
For Each pg In vsoApp.ActiveDocument.Pages
jpgName = PathName & Format(pg.Index, “0#”) & ” ” & pg.Name & “.jpg”
pg.Export jpgName
Next
vsoDoc.Close
vsoApp.Quit
Set vsoDoc = Nothing
Set vsoApp = Nothing
End Sub
#1 by Viral Sarvaiya on May 18, 2012 - 12:40 am
Thanks kelly,
its helps me. 🙂
#2 by emily on December 5, 2013 - 1:41 am
I have also found a code in vb.net to convert visio supported file formats to image, i have tried that code and it work really well, so should try it also:
http://www.aspose.com/docs/display/diagramnet/Export+Diagram+to+Image