Skip to content

Instantly share code, notes, and snippets.

@lantrix
Created February 8, 2011 05:00
Show Gist options
  • Save lantrix/815884 to your computer and use it in GitHub Desktop.
Save lantrix/815884 to your computer and use it in GitHub Desktop.
Function that exports (single page) visio diagram as png, and remembers sequence number in windows registry
Sub ExportPNG()
Dim formatExtension As String
formatExtension = ".png"
'//…or .bmp, .jpg, .png, .tif
'// Init folder, doc and counter:
folder = ThisDocument.Path & "Workshop1"
Set doc = Visio.ActiveDocument
' Create variables.
Dim sAppName As String
Dim sSection As String
Dim sKey As String
Dim sFieldName As String
Dim lRegValue As Long
Dim extNumber As String
Dim iDefault As Integer
sAppName = "Visio 2010"
sSection = "DSE"
sKey = "Workshop1 Presentation Image Number"
' The default starting number.
iDefault = 1
' If the specified form field doesn't exist,
' an error will occur.
On Error GoTo Errhandler
' Get stored registry value, if any.
lRegValue = GetSetting(sAppName, sSection, sKey, iDefault)
' If the result is zero, set to default value.
If lRegValue = 0 Then lRegValue = iDefault
' Increment and update invoice number.
SaveSetting sAppName, sSection, sKey, lRegValue + 1
'// Loop through pages:
For Each pg In doc.Pages
'// Setup the filename:
extNumber = Format(lRegValue, "000")
FileName = "slide" & extNumber
'// Append '(bkgnd)' to background pages:
If (pg.Background) Then FileName = FileName & " (bkgnd)"
'// Add the extension:
FileName = FileName & formatExtension
'// Save it:
Call pg.Export(folder & FileName)
Next
Errhandler:
If Err <> 0 Then
MsgBox Err.Description
End If
End Sub
@lantrix
Copy link
Author

lantrix commented Feb 8, 2011

One should do a manual export first to establish the parameters of the PNG file (transparency, depth, etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment