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.aspxI 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