A Visio user recently showed me a Visio 2010 document that could not be viewed with the Microsoft Visio Viewer. He could open it in Visio okay, but not in the viewer. Well I tried just removing the unused masters and styles, etc (of which there were quite a few), but that did not allow it to be viewed either. Then I tried the document.Clean() method, and, hey presto, the document could then be viewed. Unfortunately, the Clean() method is not available in the UI, so I have created a macro to make it more accessible.
The File / Info / Reduce File Size dialog shows that there are unused masters and styles :
I have created a stencil, Cleaner.vss, that contains one macro called CleanMe, which can be downloaded from the link below, and placed into My Shapes folder before opening in Visio.
It was necessary to enable macros in my installation of Visio 2010:
The macro can then be accessed from View / Macros:
The first option is to clean the document:
This option offers to remove unused masters from the document:
The next option offers to remove all unused themes, data graphics and styles:
The Visio document file size was reduced substantially:
This is the full VBA macro code:
Option Explicit
Public Sub CleanMe()
On Error GoTo errHandler
Const title As String = "bVisual Cleanser"
Dim doc As Visio.Document
If Visio.ActiveDocument Is Nothing Then
GoTo exitHere
Else
Set doc = Visio.ActiveDocument
End If
Dim iRet As Integer
iRet = MsgBox("Do you want to clean the document " & doc.Name, vbYesNoCancel, title)
If iRet = vbCancel Then
GoTo exitHere
ElseIf iRet = vbYes Then
doc.Clean
End If
iRet = MsgBox("Do you want to remove unused masters from " & doc.Name, vbYesNoCancel, title)
If iRet = vbCancel Then
GoTo exitHere
ElseIf iRet = vbYes Then
doc.RemoveHiddenInformation visRHIMasters
End If
iRet = MsgBox("Do you want to remove unused styles, themes, and other display formats from " & _
doc.Name, vbYesNoCancel, title)
If iRet = vbCancel Then
GoTo exitHere
ElseIf iRet = vbYes Then
doc.RemoveHiddenInformation visRHIStyles
End If
exitHere:
Exit Sub
errHandler:
MsgBox Err.Description
Resume exitHere
End Sub
Of course, the document must be saved in order to see the file size reduction….
Alternatively, you can download the stencil from here: Cleaner.vss
Steve Phillips says
Hi David,
A really useful post, as is the one to change the master shape for the org chart wizard, I have now created two templates one for a PBS and another for a WBS.
My next step is be able to combine both in the same template. To do this I need to have a WBS and PBS master shape in my document stencil and then have a macro that then manipulates the shape within the stencil.
For example, if the user runs a WBS Macro, this would delete the ‘Executive Shapetacular’ from the document stencil, copy and paste the WBS master shape, creating a new shape, this new shape then gets renamed to ‘Executive Shapetacular’ and set to ‘Match master by name’ in the properties; thus making it available and usable in the org chart wizard.
I am struggling with the VBA, I am not a programmer, but have done Excel VBA.
Any assistance / tips greatly appreciated.
BR
Steve
David Parker says
Sounds possible if you do it before any shape instances have been dropped. Note that Masters have both a Name and NameU property. I advise that you make them the same.