Site icon bVisual

Cleaning Visio Documents

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

Exit mobile version