Version I'm using: 2010; Version I'd like the solution in: 2013 or later
I finally resolved a longstanding issue I've seen others struggle with and I'd like to create a solution that works with later versions of Visio, but the solution I have will only work in the intermediate-term, not the long-term. First, I'll clearly describe the problem and then I'll describe a solution I'd like to use that runs VBA content from a Visio 2013 file.
-Problem: Opening a Visio file in a version later than 2010 caused it to crash.
-What Caused the Problem: files were modified and modified again (possibly dozens of times) that resulted in thousands of kilobytes worth of unused master shapes being attached to a .vsd file.
------------
-A Solution to the problem: Open in Visio 2010, Remove Unused Master Shapes by clicking: File->(on Ribbon on the Left, select Info)Reduce File Size->Check "Remove Unused Master Shapes"->Click "OK"
-A Potential Problem Using This Solution: Visio 2010 required
------------
Now that is understood, here is my question: How can I use Visio 2013 (or later) to remove unused master shapes from a file that crashes when opened using the normal GUI?
Note: I am very familiar with VBA but most of what I've done has used Excel, Word, and Access. Since files I want to operate on crash when opened the normal way, I believe the following code must be modified, by either opening a .vsd file without loading any/unused master shapes, opening it in the background(?), or operating on a file without opening it(?).
I see you can open a file read-only and "docked", but I'm not sure what "docked" means, per https://msdn.microsoft.com/en-us/library/cc160753.aspx
I found the following code, which I believe requires you to have the file open:
' Loop through each master then check across pages to see if it is used
index = vsoDocument.Masters.count
While index > 0
bMasterUsed = False
Set oMaster = vsoDocument.Masters.Item(index)
For Each oPage In vsoDocument.Pages
For Each oShape In oPage.Shapes
If oMaster.Name = oShape.Name Then
bMasterUsed = True
End If
Next
Next
' if Not used delete it from the document stencil
If bMasterUsed = False Then
oMaster.Delete
End If
index = index - 1
Wend
Can someone please help me with a nudge in the right direction by pointing me to a set of objects & methods or modify the above code to operate on another file (for simplicity, the file name can be stored in a string and the file can be in the same directory as where the code runs -- I can take it from there to operate on hundreds of files in hundreds of directories). That is, if it's possible...
Thanks in Advance,
Joe
Don't think you can cleanup the file without opening it. I'm sure a script file could be written to search directories for Visio files, then open with V2010, clean the file, save and close.
Is it only large files that are the problem? I would think not every file needs to be purged.
Alternatively, open V2010, run a similar vba file that could search for Visio files, then open, clean, and save. See this, https://msdn.microsoft.com/en-us/library/office/ff765240.aspx (https://msdn.microsoft.com/en-us/library/office/ff765240.aspx)
As for "cleanup" code, see this from David Parker, https://blog.bvisual.net/2015/01/07/cleaning-visio-documents/ (https://blog.bvisual.net/2015/01/07/cleaning-visio-documents/)
Wapperdude
Anyone did this in C# ?
I have this line in my code but it doesn't clean anything, but if I do it manually it cleans the unused document stencil. I really need to do it because we modify the master almost everyday.
VisioHelper.GetActiveWindow().Document.RemoveHiddenInformation((int)Visio.VisRemoveHiddenInfoItems.visRHIMasters + (int)Visio.VisRemoveHiddenInfoItems.visRHIStyles);
Any help would be appreciate. Thanks
Quote from: mlussier on November 08, 2017, 02:06:42 PM
Anyone did this in C# ?
I have this line in my code but it doesn't clean anything, but if I do it manually it cleans the unused document stencil. I really need to do it because we modify the master almost everyday.
VisioHelper.GetActiveWindow().Document.RemoveHiddenInformation((int)Visio.VisRemoveHiddenInfoItems.visRHIMasters + (int)Visio.VisRemoveHiddenInfoItems.visRHIStyles);
Any help would be appreciate. Thanks
Not sure if this is super helpful at this point 6 months later but I did combine a couple scripts including the one above into a single script to open a .vsd file, remove personal info, remove unused stencils, then save as a vsdx. Saved me a ton of time scripting it and reduced the file size on average 60% across thousands of files. Its posted on my blog: http://allandynes.com/2018/05/batch-converting-visio-vsd-files-to-vsdx/ Might not help the OP since you have to open the files but it might help you.