How to export multiple Visio pages to .png file (VBScript)
Introduction
This VBScript sample shows how to convert Visio page file to .png file.
Scenarios
Many companies generate technical visuals in Microsoft Visio and would like to be able to share this information on their corporate sites. The problem, however, is that most users would not be able to view the visuals in this format. One of the ways of solving this problem is converting Visio diagrams to a more universal format like PNG. But doing it manually would be time consuming, this sample can help us to batch convert Visio files, it would be very convenient.
Script
Step1: Drag one Visio file or a folder that contains Visio files to the script. It will show a message box to remind you saving the Word documents opened.
When script finishes running, you will see the results as shown in the following figure.
The result as shown below:
Here are some code snippets for your references.
Function ConvertVisioToPNG(VisioFile) 'This function is to convert a Visio file to PNG file
Dim objshell,ParentFolder,BaseName,Visioapp,Visio
Set Visioapp = CreateObject("Visio.Application")
Visioapp.Visible = False
Set Visio = Visioapp.Documents.Open(VisioFile)
Set Pages = Visioapp.ActiveDocument.Pages
Set objshell= CreateObject("scripting.filesystemobject")
ParentFolder = objshell.GetParentFolderName(VisioFile) 'Get the current folder path
BaseName = objshell.GetBaseName(VisioFile) 'Get the file name
Dim PageName,Page,Pages
For Each Page In Pages
PageName = Page.Name
Page.Export(parentFolder & "\" & BaseName & "-" & PageName & ".png")
Next
Visio.Close
Visioapp.Quit
Set objshell = Nothing
End Function
Function ConvertVisioToPNG(VisioFile) 'This function is to convert a Visio file to PNG file Dim objshell,ParentFolder,BaseName,Visioapp,Visio Set Visioapp = CreateObject("Visio.Application") Visioapp.Visible = False Set Visio = Visioapp.Documents.Open(VisioFile) Set Pages = Visioapp.ActiveDocument.Pages Set objshell= CreateObject("scripting.filesystemobject") ParentFolder = objshell.GetParentFolderName(VisioFile) 'Get the current folder path BaseName = objshell.GetBaseName(VisioFile) 'Get the file name Dim PageName,Page,Pages For Each Page In Pages PageName = Page.Name Page.Export(parentFolder & "\" & BaseName & "-" & PageName & ".png") Next Visio.Close Visioapp.Quit Set objshell = Nothing End Function
Prerequisite
Windows Office 2010 or higher version
Microsoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.