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 :

image

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:

image

The macro can then be accessed from View / Macros:

image

The first option is to clean the document:

image

This option offers to remove unused masters from the document:

image

The next option offers to remove all unused themes, data graphics and styles:

image

The Visio document file size was reduced substantially:

image

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  http://1drv.ms/14mjnJQ

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Chris Webb's BI Blog

Microsoft Analysis Services, MDX, DAX, Power Pivot, Power Query and Power BI

davecra.wordpress.com/

Microsoft Office 365 Development, and more...

PowerShell.Amsterdam

Automate, Accelerate, Accurate

johnvisiomvp

Life with Visio and other Microsoft Toys!

Title (Required)

Windows Server Essentials Tips & Tricks

Nilsandrey's Weblog

Just another WordPress.com weblog

Things that Should be Easy

Every so often (too often in the IT industry) I encounter things that should have been very easy to do but turned out to be far too complicated. My favorite topics include SharePoint, .Net development, and software architecture, especially distributed systems.

Visio Guy

Shapes, Stencils, Drawings Templates, Tutorials, Tips & Developer Info for Microsoft Visio

Hannes's Virtual Earth

Tips & Tricks around Mapping and Cloud Computing

Pluralsight blog

be smart, be clear, be visual ...

%d bloggers like this: