Reputation: 172835
I'm building an Add-in for Excel 365 and need to be able to programmatically switch the activated sheet of a workbook. This is easy and currently done using the following code:
sheet.Select();
Here's an example:
However, in case the sheet is a Chart
(in the figure Chart1
), and that chart is selected for the first time, Excel automatically switches from my custom Add-in Ribbon tab to the built-in Chart Design tab in the ribbon. By doing so, the user looses the custom tab, which is a usability issue for them.
Here's an example of how the ribbon looks like after I call sheet.Select()
:
Question: Is there a way to prevent Excel from switching the tabs, or otherwise, revert that change?
I tried calling ActivateTab
, but upon invocation, that method always throws an ArgumentException
with the following message:
Value does not fall within the expected range.
This is the code I use inside my Ribbon component:
var tab = this.Tabs.First();
var controlId = tab.ControlId;
var id = controlId.ToString();
this.RibbonUI.ActivateTab(id);// throws value does not fall within the expected range
Upvotes: 0
Views: 529
Reputation: 1
I found that the quickest way to get around this time sync caused by chart recommendations is to create a chart with the first 25 points. then click on the graph and manually change the 25 to the largest number of points in the data (i.e., 90000) in both the x and y chart data. because the chart is already made, making the number of points larger is instantaneous...
Upvotes: 0
Reputation: 172835
You can use the ActivateTabMso
method to activate the ribon tab again:
this.RibbonUI.ActivateTabMso("TabAddIns");
Upvotes: 0