自定义标签默认

我在VSTO的function区中有一个自定义选项卡。 我第一次打开Excel工作表时,默认选项卡是“首页”。我想打开我的Excel表单时,我的自定义选项卡被打开。请告诉我如何完成此操作。

我有同样的问题,看到这没有得到答复。 我在Excel 2013中使用VSTO。通过在自定义function区类(Microsoft.Office.Tools.Ribbon.RibbonBase的子类)的Load事件处理程序中添加与此类似的代码,可以轻松实现此操作:

private void YourCustomRibbon_Load(object sender, RibbonUIEventArgs e) { RibbonUI.ActivateTab("yourCustomTabName"); } 

“yourCustomTabName”是自定义RibbonTab对象的ControlId。 在RibbonTabdevise器中打开function区选项卡时,可以在ControlId属性中find它 – 正好在(Name)属性下。

您必须使用计时器来完成此操作,因为function区asynchronous加载并且没有StartupTab属性。

如果您使用的是Excel 2007,则必须通过function区的IAccessible属性访问function区,在我对Excel中的selectVSTO自定义function区问题的回答中对此进行了介绍。

 System.Timers.Timer tmr { get; set; } private void Ribbon1_Load(object sender, RibbonUIEventArgs e) { tmr = new System.Timers.Timer(500) { Enabled = true }; tmr.Elapsed += new System.Timers.ElapsedEventHandler(RibbonActivateTimer); } private void RibbonActivateTimer(object source, System.Timers.ElapsedEventArgs e) { var tab = this.Tabs.SingleOrDefault(c => ((RibbonTab)c).Label == "YourStartupTab"); if (tab != null) // check to see if ribbon tab contains the ribbon deal { if (double.Parse(Globals.ThisWorkbook.Application.Version) >= 14) //14 = xl2010 { this.RibbonUI.ActivateTab(tab.ControlId.CustomId); DeRegisterTimer(); } } } private void DeRegisterTimer() { tmr.Dispose(); }