[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1156
  • Last Modified:

In VSTO how can I load two context-senstitive ribbon tabs into an Excel project?

I have build an Excel project in VSTO using VB.Net and have included a new PivotTable context sensitive ribbon. Using the following function in ThisWorkbook.vb, it loads correctly and all works fine.

Protected Overrides Function CreateRibbonExtensibilityObject() As Microsoft.Office.Core.IRibbonExtensibility

However, I have now created another context-sensitive ribbon for PivotCharts. It seems the above 'Protected Overrides Function' can only be used to load 1 new ribbon (using Return New OdysseusToolsRibbon()) - it simply ignores the second line of code (Return New OdysseusChartRibbon()). I only need this second ribbon loaded when a PivotChart (or chart) is selected.

What event can I use to determine if a chart has been selected? ThisWorkbook_SheetSelectionChange is not triggered when you select a chart.

Also, assuming I can find when a chart is selected, how do I load the new ribbon? Is declaring it as a new ribbon enough? eg: Dim myChartRibbon As New OdysseusChartRibbon()
0
pennypearce
Asked:
pennypearce
  • 3
1 Solution
 
CodeCruiserCommented:
0
 
pennypearceAuthor Commented:
Thanks. With this article I've managed to create a new class that does detect the selection when the chart is selected from within the code. However, it is not triggered when the code finishes running and I select the chart. I've probably messed something up trying to translate this from VBA to VSTO (I'm new to VSTO).

What I've done:
- created a new class called ChartHelper and put the code from the article into it.
- In my existing class (called ExportData), I've referenced ChartHelper and assigned the chart that I build to it.
- As mentioned when I select the chart from within the code, it triggers the Select event in ChartHelper.

So, now I need to know how how to load a new context sensitive ribbon tab when a chart is selected. Once this is done once in the code, I assume the new ribbon tab will "stick" for all charts in this workbook once the code has finished running.

The chart is actually a PivotChart, but there doesn't seem to be a distinction between a chart and PivotChart code in Excel 2010.
0
 
pennypearceAuthor Commented:
I have found the solution - it turned out to be trivial!
I simply had to add the XML for the second ribbon (the chart context sensitive one) in with the XML for the first ribbon (the PivotTable context sensitive one). Because they are in the same ribbon class they load as one ribbon and all works beautifully.
0
 
pennypearceAuthor Commented:
Not sure I should be doing this as I answered the question myself, but wanted to close it off.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now