VSTO: My Favorite Feature – PPT add-in support for Ribbon and Task Pane

This is my first  of 2 posts of a great idea by Mike Hernadez of the VSTO team: VSTO: My Favorite Feature.  Mike talked a bunch of us VSTO folks into blogging our favorite things about VSTO to get some awareness out there.  Check out the ones blogged already here: 

Date 

Blogger 

Blog Address 

Feature 

02-May 

Ken Getz
Eric Carter
 

http://www.mcwtech.com/cs/blogs/keng
http://blogs.msdn.com/eric_carter/default.aspx
 

Globals Class & Ribbon Support
Outlook Form Regions
 

09-May 

Kathleen McGrath 

http://blogs.msdn.com/kathleen 

Ribbon Designer 

16-May 

Paul Stubbs 

http://blogs.msdn.com/pstubbs 

Deployment 

23-May 

Paul Ballard 

http://www.rochester-consulting.com/paul+ballard.aspx 

Custom Task Panes 

30-May 

Eric Carter
Tim Huckaby
 

http://blogs.msdn.com/eric_carter/default.aspx
http://blogs.interknowlogy.com/timhuckaby/
 

Click Once
PPT add-in support for Ribbon and Task Pane
 

Well, my post is about Powerpoint Add in Support for VSTO.  there are two amusing anecdotes around powerpoint and VSTO for me: 

1. I am the one who is always whining to the VSTO team that we need a document solution for VSTO.  I can think of a gazillion .NET applications that our customers want which would be manifested in a PowerPoint presentation.  imagine a powerpoint presentation with live data mined from a database of online systems.  that’s a world i want to live in.  it’s the ultimate executive dashboard and everyone wants that.  when i mention this in vsto presentations to audiences i am always met with a majority of heads shaking in agreement, so i know the world wants this too.  it’s been a bit challenging for me to convince the vsto team to invest in this.  i’m guessing it is becuase it would be pretty difficult for them to build, but there are members of the VSTO team that believe there is no demand for this.  that shocks me.  i will continue to whine about it.  and i would encourgage you to tell the VSTO team we need this too. 

2. but, this post is about add in support for powerpoint 2007 in VSTO.  like you, when first dealing with the ribbon, i became pretty frustrated.  now, that the learning curve is overcome i’m great, of course, but there were some cuss words thrown when things that used to be so 2nd nature suddently disappeared from the menus.  one of those was switching from normal to the slide master.  becuase i do a lot of presentations, i have to edit the slide master quite freqently.  the older i get the harder it becomes for me to remember anything, so i said to myself, “screw this. i am tired of wasting time searching for things in the ribbon so  i am going to try to figure out how to code my own menu items with VSTO and put them on my spot on the ribbon so i don’t have to constantly look for them.“   

I found some great guidance on MSDN and built a little vsto add in that creates a ribbon item that when clicked instantiates a task pane which allows you to easily switch between normal, slide master, notes master, and hand out master views while in powerpoint 2007.  now, realize that the functionality is not as impressive as how easy this was to build.  This is a great guidance app for any menu item or functionality you want to split out into your own menu item. 

Grab the source here:  Download 

once you stare at the vs.net project, it will take you less than 15 minutes to figure out.  This one is in VB, but could just as easily be in C#.  when you do a new powerpoint add in project from Visual studio, the VSTO team does almost everything for you.  they automatically stub out the COM interop you need to talk to the ribbon.  you simply need to uncomment that code: 

‘ TODO: 

‘ This is an override of the RequestService method in the ThisAddIn class. 

‘ To hook up your custom ribbon uncomment this code. 

Partial Public Class ThisAddIn 

Private ribbon As Ribbon1 

Protected Overrides Function RequestService(ByVal serviceGuid As Guid) As Object 

If serviceGuid = GetType(Office.IRibbonExtensibility).GUID Then 

If ribbon Is Nothing Then 

ribbon = New Ribbon1() 

End If 

Return ribbon 

End If 

Return MyBase.RequestService(serviceGuid) 

End Function 

End Class 

<ComVisible(True)> _ 

Public Class Ribbon1 

Implements Office.IRibbonExtensibility 

Private ribbon As Office.IRibbonUI 

Public Sub New() 

End Sub 

Public Function GetCustomUI(ByVal ribbonID As String) As String Implements Office.IRibbonExtensibility.GetCustomUI 

Return GetResourceText(“PowerPointAddIn1.Ribbon1.xml”) 

End Function 

#Region “Ribbon Callbacks” 

Public Sub OnLoad(ByVal ribbonUI As Office.IRibbonUI) 

Me.ribbon = ribbonUI 

End Sub 

Public Sub OnToggleButton1(ByVal control As Office.IRibbonControl, ByVal isPressed As Boolean) 

Globals.ThisAddIn.MyTaskPane.Visible = isPressed 

End Sub 

#End Region 

They automatically create a little XML manifest for you (ribbon1.xml) that allows you to name your ribbon item and it’s properties and ties the thing together.   

i built a simple user control that allows you to switch between the views and then one of the most powerful things about VSTO is the one line of code it takes to bind the user control to the task pane: 

myControl = New UserControl1 

MyTaskPane = Me.CustomTaskPanes.Add(myControl, “My Custom Task Pane”) 

Try it out.  build the project and run it. you’ll see a custom task panes button on the add-ins section of the ribbon in powerpoint.  when you choose that it will light up the task pane with the combo box in it that allows you to quickly and easily change views while working in PowerPoint. 

Leave a Reply

Your email address will not be published. Required fields are marked *