3 4
A Microsoft Visio user interface file (VSU) is a means of saving a custom user interface between Visio instances. If your solution makes extensive changes to the Visio user interface, and it's unlikely that your users will run other solutions that also make user interface changes, a VSU file might be a more efficient way of providing a custom user interface.
Beginning with Microsoft Visio 2000, Visio uses a VSU file to preserve user customizations. The first time a user customizes the Visio user interface using the Customize command (on the View menu, click Toolbars), the Visio instance takes a snapshot of the user interface currently in effect (including customizationssupplied by Visio solutions) and, when the user exits the Visio instance, stores it in a file called Custom . vsuin the user's profile folder.
If your solution employs a VSU file to supply a custom user interface, keep the following in mind:
If you've made extensive user interface changes and intend to save your custom user interface to a VSU file, use the SaveToFile method of the UIObject object. For example:
uiObj.SaveToFile("c:\solutions\mytools.vsu")
You can load a custom user interface file by setting the custom user interface for the Application object. You can also load a custom user interface file (VSU) when an event occurs, such as opening a document.
To load a custom user interface file for an Application object, set the following properties of the object to the name of the custom user interface file:
For example, to load a custom user interface file each time the users starts Visio, use this statement:
Visio.Application.CustomToolbarsFile = "c:\solutions\mytools.vsu"
You need to set these properties for the Application object only once. These properties set the value of the CustomMenusFile and CustomToolbarsFile entries in the Microsoft Windows registry and tell Visio the location of the corresponding custom interface file. If a path is not specified, Visio looks in the folders along the Visio Add-ons path, specified on the File Paths tab (on the Tools menu, click Options). If the specified file cannot be located, or if the registry key is deleted or modified, Visio reverts to the built-in Visio user interface.
To load a custom user interface file when an event occurs, such as opening a document, put the code in the appropriate event for the Document object.
To load a custom user interface file each time a document is opened, use this statement in the DocumentOpened event procedure for the Document object:
ThisDocument.CustomMenusFile = "c:\solutions\mytools.vsu"
If you are programming in an external development environment such as Microsoft Visual Basic, you can load a custom user interface file, make changes to it, and then save the changes to the file.
To load a custom user interface file, use the LoadFromFile method. For example:
UiObj.LoadFromFile "shortcut.vsu" ...'Make UI changes uiObj.SaveToFile "c:\solutions\mytools.vsu"
If your solution customizes the Visio user interface, it's a good idea to restore the original user interface when your solution finishes running. If your solution detected custom menus or custom toolbars on the user's system, or if the user might have customized the user interface while your solution was running, it should reverse its user interface changes by removing the items it added and restoring those it removed.
If you can be certain that no other customizations should be preserved, you can clear custom menus and custom toolbars to quickly restore the built-in Visio user interface. Clearing custom menus and toolbars does not erase a user's Custom.vsu file, but it does cause Visio to stop using it.
To restore the built-in Visio menus and accelerators, use the ClearCustomMenus method of the Document (or Application) object. To restore the built-in Visio toolbars, use the ClearCustomToolbars method of the Document (or Application) object. For example, to clear the custom menus for a Document object, use this statement:
ThisDocument.ClearCustomMenus
For example, to clear custom toolbars for the Application object, use this statement:
Visio.Application.ClearCustomToolbars
The next time the document is opened or a Visio instance is run, it uses the built-in Visio user interface.