In my drawing files, each page is a figure, and I save it to an SVG file named after that page. I'm a keyboard shortcut guy and I got tired of going through all the Save As dialog gymnastics, so I created three macros to automate the process:
- SaveThisPage – saves the current drawing page as an SVG file named after the page name.
- SaveAllPages – similarly saves all pages in the current Visio drawing document.
- SaveAllWindows – similarly saves all pages of all drawing documents open in the current Visio instance.
Here's the code:
Public Sub SaveThisPage()
Dim PgObj As Visio.Page
Dim filename As String
Dim PgName As String
'Set a handle to currently active page
Set PgObj = ActiveWindow.Page
'Skip if page is empty
If PgObj.Shapes.Count = 0 Then Exit Sub
' Select everything
Application.ActiveWindow.SelectAll
'Get Page name
PgName = PgObj.Name
'Create path to save svg file
filename = Application.ActiveDocument.Path & PgName & ".svg"
'Export the page as svg file
ActiveWindow.Selection.Export filename
'Clean Up
Set PgObj = Nothing
End Sub
Public Sub SaveAllPages()
Dim PgObj As Visio.Page
Dim Pgs As Visio.Pages
Dim filename As String
Dim PgName As String
Dim iPgs As Integer
'Set a handle to the pages collection
Set Pgs = Application.ActiveDocument.Pages
'Loop Pages collections
For iPgs = 1 To Pgs.Count
'Set a handle to a page
Set PgObj = Pgs(iPgs)
ActiveWindow.Page = PgObj
SaveThisPage
Next iPgs
'Clean Up
Set PgObj = Nothing
Set Pgs = Nothing
End Sub
Public Sub SaveAllWindows()
Dim vsoApplication As Visio.Application
Dim vsoWindows As Visio.Windows
Dim intCounter As Integer
'Get the Windows collection.
Set vsoApplication = Application
Set vsoWindows = vsoApplication.Windows
For intCounter = 1 To vsoWindows.Count
vsoWindows.Item(intCounter).Activate
SaveAllPages
Next intCounter
End Sub
I'm a VBA newbie, so this code might be awful and I don't know it. But hey, you get what you pay for! Also, I use Visio 2016; this might or might not work in other versions.
I put this block of code into a module called QuickSave, then I configured SaveThisPage to use Ctrl-q and SaveAllPages to use Ctrl-Q. (I run SaveAllWindows manually, whenever there is a need to regenerate everything.)
We use a shapes template file to create our drawings. I put the QuickSave module into the template file, but the macro hotkeys don't work from there. So, I then manually copy the QuickSave module from the template file to each of my drawing files. It's a pain but it works. I was able to automate this module installation method somewhat; if anyone's interested, I can share how.