NOTE: The code in this post is explained in the Project 2010 SDK article, How to: Use Managed Code to Add a Custom Command to the Ribbon.
It is instructive to do the same exercise with VSTO. There are many advantages to using a VSTO add-in, including the ability to easily publish the solution with ClickOnce. As the thread discussion notes, there is no good way to distribute the VBA solution in the Global.MPT to other users.
Basically, use Visual Studio 2010 and create a new Project 2010 Add-in project. Use the .NET Framework 3.5. You can use C# or VB.
- There are no changes necessary in the ThisAddIn.cs (or ThisAddIn.vb) file.
- Right-click the project in Solution Explorer, and add a new item -- add a Ribbon (Visual Designer) item. In the code below, it is named ManualTaskColor.cs (or ManualTaskColor.vb).
- In the ManualTaskcolor.cs [Design] view, drag a Tab from the Toolbox\Office Ribbon Controls to the ribbon.
- Drag a Group to the new tab.
- Drag a Button (or a ToggleButton) to the group. Change the labels, button image, etc. as you wish.
- To match the VBA example in the SDK, you can set the OfficeImageID property of the button to DiagramTargetInsertClassic.
- Select the new button in the ribbon Design view, click the Events icon in the Properties pane, and then double-click the Click event to create the button_Click event handler.
Here is the C# code in the ManualTaskColor.cs file. The code is ported from the VBA code in the SDK article:
using MSProject = Microsoft.Office.Interop.MSProject;
public partial class ManualTaskColor
private const int WHITE = 0xFFFFFF;
private const int LIGHT_BLUE = 0xF0D9C6;
private void ManualTaskColor_Load(object sender, RibbonUIEventArgs e)
app = Globals.ThisAddIn.Application;
private void tBtnManualTaskColor_Click(object sender, RibbonControlEventArgs e)
private void ToggleManualTasksColor()
project = app.ActiveProject;
string column = "Name";
bool rowRelative = false;
foreach (MSProject.Task t in project.Tasks)
if ((t != null) && !(bool)t.Summary)
app.SelectTaskField(t.ID, column, rowRelative);
rgbColor = app.ActiveCell.CellColorEx;
// Check whether the manual task color is white.
if (rgbColor == WHITE)
app.Font32Ex(CellColor:LIGHT_BLUE); // Change the background to light blue.
app.Font32Ex(CellColor:WHITE); // Change the background to white.
// The task is automatically scheduled, so change the background to white.
_________________Just for kicks, here is the VB code in the ManualTaskColor.vb file, in you do the project in VB. The code is ported from the C# example above:
Imports MSProject = Microsoft.Office.Interop.MSProject
Public Class ManualTaskColor
Private Const WHITE As Integer = &HFFFFFF
Private Const LIGHT_BLUE As Integer = &HF0D9C6
Dim app As MSProject.Application
Dim project As MSProject.Project
Private Sub ManualTaskColor_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) _
app = Globals.ThisAddIn.Application
Private Sub tBtnManualTaskColor_Click(ByVal sender As System.Object, _
ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) _
project = app.ActiveProject
Dim column As String = "Name"
Dim rowRelative As Boolean = False
Dim rgbColor As Integer
For Each t As MSProject.Task In project.Tasks
If (Not t Is Nothing) And (Not t.Summary) Then
app.SelectTaskField(t.ID, column, rowRelative)
rgbColor = app.ActiveCell.CellColorEx
If (t.Manual) Then
' Check whether the manual task color is white.
If (rgbColor = WHITE) Then
app.Font32Ex(CellColor:=LIGHT_BLUE) ' Change the background to light blue.
app.Font32Ex(CellColor:=WHITE) ' Change the background to white.
' The task is automatically scheduled, so change the background to white.
- Editado Jim CorbinModerator martes, 29 de junio de 2010 19:46 Updated article in SDK
Todas las respuestas
Are there any examples where the ribbon is implemented in Project using ribbon xml with callbacks (VSTO and C#)? I am getting errors doing this in Project using the same callback signatures that work in other Office apps. If not, can the method shown here work with Visual Studio 2008?
SharePoint, Project Server, and Project client were developed with .NET 3.5. Using .NET 4.0 in some cases doesn't work with Project Server applications, such as workflow and configuring WCF. It's probably taking a chance if you mix 3.5 and 4.0 components, but I haven't done a lot of testing with 4.0.
Visual Studio 2010 is required because it includes the templates for Project 2010 and correctly creates event handlers. The SDK update later in May includes an article that creates an event handler. I don't yet have an example using ribbon XML with callbacks.
The May update of the Project 2010 SDK includes the How to: Use Managed Code to Add a Custom Command to the Ribbon article, and the SDK download includes the complete code.
To all --
I made a MSDN presentation on this to use the VSTO in VS2010 and VB.NET. I create a ribbon and some executable code.
If you wish a copy of the code (it is free) you contact me by visiting my blog http://www.msprojectblog.com
When I dig out the actual Microsoft link, I will edit this post.
jeaksel at yahoo dot com
I am looking for resources on doing the opposite. I want to remove/hide things on the ribbon. One example is on the Project Center, under new I want to remove/hide the From SharePoint list option.
Also, does anyone know how to find the ID of the existing ribbon controls.
Project 2007 VSTO issue: I'm not sure if you've tried to create a VSTO add-in targeting Project 2007 - but I'd be glad if you could verify the following:
- Create a VSTO addin for Project 2007 using VS2008 or VS2010 targeting 3.5 - the addin doesn't have to do anything at all - just using the code in th newly created "empty" template will suffice.
- Debug the addin or publish/install - doesn't matter which - and open Project 2007 with the addin loaded
- Create an Excel Visual Report
- Close the Visual Report dialogue box
- Close Project
Doesn't happen on Project 2010.
Looking at the SDK pre-requisites here: http://www.microsoft.com/en-gb/download/details.aspx?id=15511 it appears that XP is not supported.
I am seeing crashes with a simple ribbon addin (similar to that above) for Project 2010 standard when tested on XP machines and am being told this is because XP is not supported.
Can you categorically tell me if writing a VSTO addin for Project 2010, to customise a Ribbon is supported on Win 7 AND XP-SP3 (with .NET 3.5)?