Yesterday Microsoft announced the availability of the BETA for Visio 2010. If you have not seen my blog post on this click here and download your copy of the BETA today.
Today I want to share with you a guide that I developed which walks you through the process for adding a Ribbon based UI to your VSTO based add-ins. I also want to share with you a set of sample add-ins which incorporate my best practices for working with ribbons in Visio based add-ins.
This guide will also point out that you are now able to provide support for both CommandBars and Ribbons in the same add-in so that it can be used in either Visio 2007 or Visio 2010. Of course this requires that you not make use of any new Visio 2010 APIs, including the new Application.RegisterRibbonX() method which allows you to add a document level ribbon.
Get my Visio Ribbon Guide and sample source code here.
My source code samples include:
- Application Level sample showing how to add a tab to the ribbon no matter what document is active. This includes enabling and disabling items on the ribbon tab based on the active document.
- This also includes a sample showing how to add a tab to the File tab view.
- Document Level sample showing how to add a tab to the ribbon for a specific document so that it will only be visible/accessible if that document is the active document.
- This also includes a sample showing how to add your own menu items to the right-click shape menu.
- VBA sample that demonstrate how you can use RibbonX with a VBA based solution.
For additional documentation on ribbon extensibility refer to these sites:
Backstage extensibility in Office 2010 – This article is a high level overview showing the level of customization that can be accomplished with RibbonX in Office 2010 applications, including Visio 2010 ;-)
Extending the interface in Outlook 2010 – This article is based on Outlook but has many RibbonX samples for various interface items.
Using RibbonX with C++ and ATL – If you are not using .NET take a look at this.
Visio 2010 adds Live Preview functionality to stencils so that you can provide a rich view of your custom shapes.
Read this article from the product team to learn how to enable this functionality in your custom stencils, Live Rendering Shapes in Visio 2010.
Click here to download a sample stencil that uses this new functionality, demonstrating how you can crop the view to get the best possible images for your masters.
With the release of Visio 2010 you have the choice to install either the 32bit version or the 64bit version. What version you are able to install depends on:
- The target operating system. In order to install 64bit Visio you must have a 64bit operating system.
- The version of Office that you have installed. Office applications and Visio share common components. If you have 32bit Office installed you can only install 32bit Visio and vise versa.
Visual Studio Tools for Office (VSTO)
If you are using VSTO as the architecture for your Visio based add-ins you are in luck. These add-ins are based on managed code (C#, VB.NET, etc) and compile to MSIL, meaning that when the VSTO runtime executes a VSTO add-in, the .NET runtime compiles the MSIL to native code based on the target platform. In other words, if your add-in is VSTO based then there are no changes that you have to make to your code in order to support both 32 bit and 64 bit versions of Visio 2010.
Anything other than VSTO (VSL, COM add-in, etc.)
If you are not using VSTO as the architecture for your Visio based add-ins then you will want to build both 32 bit and 64 bit versions of your add-ins.
For additional information read this article which explains 32 bit / 64 bit issues in Office 2010
Compatibility Between the 32-bit and 64-bit Versions of Office 2010
FYI – this article also discusses changes to VBA for the 64 bit environment.
Attention Visio developers, the BETA for Microsoft Visio Premium 2010 has just shipped and can be downloaded from the following links:
Microsoft Visio Premium 2010 (x86)
Microsoft Visio Premium 2010 (x64)
In you have not visited the Product Team’s blog do so now at http://blogs.msdn.com/visio to read about new functionality directly from the product team.
But what about the SharePoint 2010 BETA you ask, well that has shipped too.
Download the Microsoft SharePoint 2010 BETA
When you register to download the BETA, make sure you get the Enterprise CAL so that you can check out the new Visio Services functionality…
Stay tuned to my blog for more articles on Visio 2010 development including Visio Services development.
With the release of Visio 2007 you could no longer rely on just a check to see if Visio was installed, you also needed to know the Edition or SKU that was installed if you were to use the Data Linking or Data Graphic capabilities via the API. Now with the release of Visio 2010 Premium there is another reason to check the edition at runtime.
Visio 2010 Premium includes new functionality for rules based validation which is available via the API, however, this functionality and APIs are only available to user of the Premium edition, meaning that if your solution uses these APIs you will need to make sure that they are available before calling them.
CurrentEdition is a new property that has been added to the Application class which is set to one of the following values at runtime:
visEditionStandard
visEditionProfessional
visEditionPremium
Using this new property you can determine if the running instance of Visio that is hosting your solution supports rules validation.
Here are two simple properties that you can add to your ThisAddin class (if you are using VSTO) that you can use to:
Check for Data features support:
internal bool DoesVisioSupportDataFeatures
{
get
{
bool retVal = false;
if (this.Application != null &&
this.Application.TypelibMinorVersion >= 12)
{
retVal = this.Application.DataFeaturesEnabled;
}
return retVal;
}
}
Check for Process features support: internal bool DoesVisioSupportProcessFeatures
{
get
{
bool retVal = false;
if (this.Application != null &&
this.Application.TypelibMinorVersion >= 14)
{
if (this.Application.CurrentEdition ==
Visio.VisEdition.visEditionPremium)
{
retVal = true;
}
}
return retVal;
}
}
The Visio Guy site released a new tool that will help you customize the icon on the Server shape that ships with Visio so that you can easily create a server shape that represents your individual needs.

Take a look at the article and download the tool today.
I just wanted to publicize the Visio Product team’s blog which is being updated with important articles about the new features and APIs that will be available with the release of Visio 2010.
Recently we released a new add-in for Visio 2007 that allows you to connect your diagrams to data from an Operations Manager server.

To download this new add-in or to read more details please visit the System Center Operations Manager blog.
Visio 2007 provides the capability to add data to your diagrams from several supported data sources such as Access, Excel, SharePoint, and SQL, etc. You can also use this capability within your Visio add-ins as the Visio object model provides many objects, methods, and properties for adding, removing, and manipulating DataRecordsets within your add-in.
Here is some sample code that demonstrates taking a .NET DataTable and adding it to a Visio drawing…
// create a new instance of our DataTable
TeamDataSet.TeamMembersDataTable data = new TeamDataSet.TeamMembersDataTable();
// read the sample data from a file to populate our data table
data.ReadXml(dataPath + "sample data.xml");
// convert the .NET DataTable to ADO Recordset XML using this class provided by the Visio 2007 SDK
string newXmlData = ADONET2ADO.ConvertToAdoRecordsetXml(data);
// create a new datarecordset in our Visio drawing using the converted XML
Visio.DataRecordset newRecordSet = this.VisioDocument.DataRecordsets.AddFromXML(newXmlData, 0, "Team Members");
Once this DataRecordset has been added to the document you can open the External Data window to view the data within your diagram and link the records in this DataRecordset to the shapes in your diagrams.
One issue I do want to point out is a small change that I made to the ADONET2ADO class that shipped with the Visio 2007 SDK. Attached to this article is an updated version of the ADONET2ADO class that contains one small fix to the TranslateType function for the System.String case. When the SDK was released this case converted System.String to ADODB.DataTypeEnum.adVarChar but this type does not handle Unicode which is very common with System.String since strings .NET are Unicode based.
Click here to download the updated ADONET2ADO class.
The System Center forum hosts a download that contains three new stencils dedicated to System Center Operations Manager. These stencils contain approximately 64 shapes
You can easily add these stencils to your My Shapes menu by unzipping the content of the download into your My Shapes folder under My Documents (XP) or Documents (Vista)…
Each shape is a high quality raster based image with no shape data or data graphics attached so you have a fresh canvas to build your Operations Manager diagrams.
Click here to download the System Center Operations Manager shapes.
I recently received a request from a user who wanted the ability to:
1. rotate the text for the Bracket Interval shape to an angle such as 45deg.
2. display the interval name above the date instead of below.
I took the built-in shape and customized it to support these two requirements, allowing you to have a Bracket Interval shape that looks like this…
This new shape has an additional right-click menu item that toggles the text from ‘Horizontal Text’ to ‘Angled Text’. When set to ‘Angled Text’ a new control handle appears that allows you to set the angle of the text.
Feel free to download my Visio diagram that contains this new shape and use this shape in your timeline diagrams.
(updated 6/11/09 – added support for a dialog to allow you to set the interval between slides)
Recently I was asked if it was possible to set a timer to automatically switch to the next page when in full screen mode, producing a slide show style presentation mode.
I decided to do this using VBA as this code can easily be added to any Visio document that needs this functionality.
FYI, when the slide show macro is running and the last page in the document is reached, the slide show will continue with the first page via a continuous loop.
To add this functionality to your document:
- Open your document
- Open the Visual Basic editor, ALT + F11 or from the Tools > Macro > Visual Basic Editor menu item
- Paste the code below into the ThisDocument module via the Visual Basic editor
- By default the editor opens the ThisDocument module.
Start the slide show
From the Tools > Macros > ThisDocument menu select StartSlideShow
Stop the slide show
Simply press the ESC key. This will exit full screen mode and also trigger the timer in the macro to stop, returning you to the Visio application window.
Set the Interval
From the Tools >Macros > ThisDocument menu select SetInterval
Download the Visio diagram that contains this code here.
Here is the VBA code:
Option Explicit
Private WithEvents g_vsoApplication As Visio.Application
Private g_interval As Integer
Private Const DEFAULT_INTERVAL As Integer = 5
Private g_fullScreen As Boolean
Public Sub SetInterval()
Dim entryVal As String
Dim entryError As Boolean
reEnterValue:
' init our error flag
entryError = False
' determine if we show the default value or the last entered value
Dim initVal As Integer
If Not (g_interval = DEFAULT_INTERVAL) And Not (g_interval = 0) Then
initVal = g_interval
Else
initVal = DEFAULT_INTERVAL
End If
' get a new value from the user
entryVal = InputBox("Enter the interval (in seconds 1 - 60)", "Set Slide Show interval", initVal)
If Len(entryVal) = 0 Then
' the user pressed cancel
Exit Sub
End If
Dim tmpInterval As Integer
If IsNumeric(entryVal) Then
tmpInterval = Conversion.CInt(entryVal)
If tmpInterval < 1 Or tmpInterval > 60 Then
entryError = True
End If
Else
entryError = True
End If
If entryError Then
MsgBox "Please enter a value between 1 - 60"
GoTo reEnterValue
End If
g_interval = tmpInterval
End Sub
Public Sub StartSlideShow()
Set g_vsoApplication = Application
Dim iNextPage As Integer
iNextPage = 1
' set the first page
ActiveWindow.Page = ThisDocument.Pages(iNextPage)
' enter full screen mode
Application.DoCmd visCmdFullScreenMode
g_fullScreen = True
Do While g_fullScreen
' start timer
Dim pTime, pStart, pEnd, tTime, lTime
'five second loop
pTime = g_interval
pStart = Timer
Do While (Timer < pStart + pTime) And g_fullScreen = True
DoEvents
lTime = (pStart + pTime) - Timer
Loop
' get the next page index that we need to switch to
If iNextPage = ThisDocument.Pages.Count Then
iNextPage = 0
End If
iNextPage = iNextPage + 1
' get the next page and switch to it
Dim vsoNextPage As Visio.Page
Set vsoNextPage = ThisDocument.Pages(iNextPage)
ActiveWindow.Page = vsoNextPage
' reset timer
pEnd = Timer
tTime = pEnd - pStart
Loop
End Sub
Private Sub g_vsoApplication_KeyPress(ByVal KeyAscii As Long, CancelDefault As Boolean)
' kill the code on any keypress
g_fullScreen = False
End Sub
After I posted my source for managing CommandBarButton and CommandBarPopup objects I received a few requests to include management of CommandBarButtons that control the state of AnchorBar windows.
As you know you can add your own windows within the Visio drawing window, similar to the Shape Data window. These type of windows are typically controlled via a menu item that toggles its state or caption depending on the visible state of the window. For example, the caption of the menu item changes or the visual state or the menu item switches between a pushed or unpushed state.
Good news. I updated my CommandBar management code to support this functionality.
Included in this update is my new VisioCommandBarButtonForAnchorWindow class. This new class contains the functionality for toggling either the Caption property or the State property of the CommandBarButton based on the Visible state of your AnchorBar window.
Getting Started
After you download this source you should be able to compile it and run it. You will need VS 2008, VSTO 3.0, and Visio 2007. Visio 2007 will also need to have .NET Programmability Support installed (PIA).
Feel free to add the UIMgr.cs and the VisioCommandBars.cs source files to your own project. In most cases all you will need to do is change the AddUI method to add your specific CommandBarButtons or PopUps.
Click here to download the sample VSTO based add-in that demonstrates how these wrapper classes are used, along with the full source to the wrapper classes.
Recently I have noticed a few add-ins that lock customization on the MenuBar object after the add-in has made its changes, i.e. adding a custom menu. There are valid reasons for using this functionality but you also have to consider the impact to other add-ins that may be installed.
Example:
menuBar.Protection = MsoBarProtection.msoBarNoCustomize
If you are setting the Protection property on the MenuBar object you are preventing the user from being able to make modifications to the entire MenuBar object. This will protect your custom menu but it will also prevent any other add-ins from making changes to the MenuBar object.
If another add-in attempts to customize the CommandBars after this property is set the add-in will receive the following exception, which is not easily interpreted as a protection issue…

Error HRESULT E_FAIL has been returned from a call to a COM component.
Best Practices
1. Do not set the Protection property of the MenuBar object unless it is absolutely necessary. Rather than setting this property add the additional logic to manage your CommandBar objects. For example, check to see if your UI changes exist and if not simply add them back. I typically do this when my add-in is first loaded.
2. I started adding the following code to all of my add-ins. Before I attempt to make modifications to the CommandBar objects I check the Protection property and reset it to msoBarNoCustomize before attempting to make my changes. This ensures that my add-in is able to make changes to the CommandBar objects.
...
CommandBars commandBars = Globals.ThisAddIn.Application.CommandBars as CommandBars;
CommandBar menuBar = commandBars["Menu Bar"] as CommandBar;
if ((menuBar.Protection & MsoBarProtection.msoBarNoCustomize) == MsoBarProtection.msoBarNoCustomize)
{
// make sure we can always add out UI
menuBar.Protection = MsoBarProtection.msoBarNoProtection;
}
...
Most add-ins that are developed for Visio make modifications to the Visio menu and toolbars. The add-in developer is responsible for making the appropriate changes to the Visio UI in a manner that does not affect the operation of Visio or other add-ins that maybe installed. They are also responsible for cleaning up their changes.
Uninstall is a typical scenario that is often overlooked when making changes to the Visio menus and toolbars. In this scenario the user has installed an add-in for Visio but at some point decided to uninstall the add-in. After the user uninstalls the add-in they notice there are still menus or toolbars from the add-in that should have been removed. At this point the user is left to manually clean up these items using the Customize dialog by clicking on the View > Toolbars > Customize menu.
For example, by clicking on the Menu Bar item as shown above and then clicking on the Reset button, the main menu in Visio will be reset back to the default, removing any customizations that have been made by the user or by any add-ins.
I have seen instances where the Reset button is not enabled. This could be because an add-in explicitly set protection on a menu or toolbar to try and keep someone from modifying it or removing it. In this situation you are left with the option of finding the file that saves all UI changes and deleting it from your system. This file is called ‘ custom12.vsu ’ and is located in your profile folder, typically ‘ C:\Users\[user name]\AppData\Roaming\Microsoft\Visio ’. If you deleted this file (while Visio is not running) all menu and toolbar changes will be removed.
My ResetUI Tool
I have a small macro that resets all changes made to the menus and toolbars in the attached Visio document.
Click here to download this document.
When you open this document VBA macros are disabled by default so you have to enable the macros in the document by clicking the button on the Security Warning bar…
After you enable the macros in this document you will be asked if you want to reset the UI. Answering Yes to this will run the ResetUI macro which calls reset on all built-in menus and toolbars, disables any protection that has been set on any of the menus or toolbars, and removes any custom menus or toolbars that were added by third parties.