vbavisio

Split file by pages including background


tl;dr Is there an efficient way using VBA to split a multipage Visio file into different files per foreground page and including a background page?

A simpler version of this question (excluding the background page) has been asked several times over the years, and each time the answer is to use Paul Heber's Visio Super Utilities. I'm sure this tool is wonderful, but unfortunately I can't use it due to company restrictions.

I have a file with ~200 pages, all utilizing the same background template to easily modify common elements. Loading the whole file is unwieldy for daily use, and only a few of the pages are needed by an individual user. I'd like to split it into individual files for convenience and security.

I've come up with 2 approaches for this. I don't have access to Visio on my home machine, so I'll just explain the processes:

  1. Set an UndoScope to delete every page except the ones I'm interested in. Save, then undo the operation and repeat. This means there will be a 200ish page undo operation repeated 200ish times. I haven't done any testing, but I bet this is a performance nightmare and prone to errors.

  2. Open a new instance of Visio and copy individual pages to it. Loop through pages once to find the background (if unknown), transfer it. Loop again to transfer each foreground, save as new file, then delete the page. This seems better but requires a method for transferring pages. I'm not aware of a simple way to do that while preserving layer/protection settings.

I'm hoping there's some 3rd highly efficient solution that I'm unaware of. In a perfect world, it'd be included in Document.SaveAsEx. In a less perfect world, it'd be some kind of Page.ExcludeDuringSave flag I could set. Any help/advice is appreciated.


Solution

  • I've just built a completely online solution for this for fun :) It splits the Visio file on the XML level (i.e. works without Visio installed) right in the browser, by removing extra unrelated pages.

    Here: https://webtools.unmanagedvisio.com/splitpages

    You are welcome to try it out, and send me any feedback. The size of the file may be an issue, or maybe not. I've tried with 2Mb file, looks fine. Also, I have not checked what happens if you have formulas in shapes on one page referring to another page, those formulas will be broken most probably (#ref)

    The solution is completely open source