使多个工作簿的Excel 2013中的功能区控件无效 [英] Invalidate ribbon control in Excel 2013 for multiple workbooks

查看:95
本文介绍了使多个工作簿的Excel 2013中的功能区控件无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的功能区,在其中添加了一个包含切换按钮的选项卡.此切换按钮具有getPressed属性,该属性链接到一个回调函数,该函数返回切换按钮的按下状态.切换按钮的目的是显示/隐藏自定义任务窗格.效果很好.

I have a customized ribbon where I added a tab containing a toggle button. This toggle button has a getPressed attribute which is linked to a callback function returning the pressed state of the toggle button. The purpose of the toggle button is to display/hide a custom task pane. This works fine.

但是,我的问题是在Excel 2013中,如果我打开了两个或更多工作簿,则在使切换按钮无效时,只会更新活动工作簿中的一个.我还想更新其他工作簿上的切换按钮的按下状态,因为自定义任务窗格在所有工作簿中都可见或不可见.

However, my issue is that in Excel 2013, if I have two or more workbooks open, when I invalidate the toggle button, only the one of the active workbook is updated. I also want to update the pressed state of the toggle buttons on the other workbooks as the custom task pane is either visible or invisible in all workbooks.

任何人都知道如何使Excel 2013中所有工作簿的功能区中的控件无效吗?

Anyone knows how to do invalidate a control in the ribbon of all workbooks in Excel 2013?

我正在使用vb.net和excel-dna.切换按钮的定义如下:

I am using vb.net and excel-dna. The toggle button is defined like that:

<toggleButton id="toggleButtonInputData" size="large" onAction="rxToggleButton_onAction" getPressed="rxToggleButton_getPressed" getImage="rxButton_GetImage" getLabel="rxbutton_GetLabel" getEnabled="rxGenericControl_GetEnabled" visible="true"/>

回调函数是:

 Function rxToggleButton_GetPressed(ctl As CustomUI.IRibbonControl) As Object
        Select Case ctl.Id
            Case "toggleButtonInputData"
                Return CTP_InputData.IsToggleButtonPressed
        End Select
    End Function

要使切换按钮无效,请使用:

To invalidate the toggle button I use :

Public Sub CTP_InputData_VisibleStateChange() Handles CTP_InputData.VisibleStateChange
        XLRibbon.myRibbon.InvalidateControl("toggleButtonInputData")
End Sub

推荐答案

仅针对活动工作簿的功能区处理无效.但是,当您随后切换到另一个工作簿时,回调将再次触发,并立即应用于新工作簿的功能区.

The Invalidation is only processed for the active workbook's ribbon. But when you then switch to another workbook, the callbacks will fire again and will now be applied to the ribbon of the new workbook.

Excel 2013中存在与该切换有关的错误和一些怪癖:

There's a bug and some quirks in Excel 2013 related to this switching:

如果单击标题栏或要激活的工作簿的功能区,则所有操作均按预期进行.但是,如果在要激活的工作簿中单击一个单元格,则会得到两个回调-第一个回调应用于停用的工作簿的功能区,第二个回调应用于激活的工作簿的功能区.问题在于您无法区分(在您的回调中)您是否正在被要求停用的书.(使用COM事件也无济于事,在所有COM Workbook-和Window-(De)Activate事件都触发后,两个回调都会发生.

If you click on the title bar or the ribbon of the workbook you want to activate, everything works as expected. But if you click on a cell in the workbook you're activating, you get two callbacks - the first is applied to the deactivating workbook's ribbon, and the second is applied to the activating workbook's ribbon. The problem is that you cannot distinguish (in your callback) whether you are getting called for the deactivating book. (Using COM events doesn't help either, both callbacks happen after all the COM Workbook- and Window- (De)Activate events have fired.

除了这种古怪的行为,Excel 2013中一个明显的错误是IRibbonControl.Context未设置为正确的窗口-在两个回调中,它都反映了激活窗口,尽管第一个回调将应用于停用窗口窗口.

Apart from this quirky behaviour, one clear bug in Excel 2013 is that the IRibbonControl.Context is not set to the correct window - in both of the callbacks it reflects the activating window, though the first callback will be applied to the deactivating window.

这里是有关此问题的详细讨论:

Here's a detailed discussion on the issue: https://social.msdn.microsoft.com/Forums/windowsserver/en-US/a3dade87-1df7-46ec-8876-437194d7553e/how-to-reference-the-correct-workbook-from-a-control-in-a-ribbon-callback?forum=exceldev

总而言之,您无法很好地控制已停用色带的状态.但是,如果您只担心活动的功能区,则Invalidate可以很好地工作,但是您必须仅在激活后才能期待回调.

In summary, you don't have good control over the state of deactivated ribbons. But if you are only worried about the active ribbon, Invalidate works fine, but you must expect the callback only upon activation.

这篇关于使多个工作簿的Excel 2013中的功能区控件无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆