gpt4 book ai didi

excel - 打开工作表时如何以编程方式更改 Excel 2007 功能区上的标签值

转载 作者:行者123 更新时间:2023-12-04 22:04:38 24 4
gpt4 key购买 nike

在 Excel 2007 功能区上,我添加了一个带有按钮的新组。我需要能够根据第一次打开工作表时检查的条件(例如 onload 事件)将标签文本从“ABC_Execute”更改为“其他内容” - 如何在 VBA 中做到这一点?

用于自定义功能区的示例代码:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab id="customTab" label="ABC" insertAfterMso="TabHome">
<group id="customGroup" label="ABC Tools">
<button id="customButton1" label="ABC_Execute" size="large" onAction="Begin" imageMso="Bold" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>

谢谢。

最佳答案

您需要将 getLabel 回调添加到您的 CustomUI:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="rx_rib_on_load">
<ribbon>
<tabs>
<tab id="customTab" label="ABC" insertAfterMso="TabHome">
<group id="customGroup" label="ABC Tools">
<button id="customButton1" getLabel="rx_getLabel" size="large" onAction="Begin" imageMso="Bold" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>

然后在工作簿模块中:
Sub rx_getLabel(control As IRibbonControl, ByRef returnedVal)
returnedVal = ThisWorkbook.Sheets("Sheet1").Range("A1").Value
End Sub

例如。如果您需要随后更改该值,您将需要一个 onLoad 回调,以便您可以在需要时使控件/功能区无效。

关于excel - 打开工作表时如何以编程方式更改 Excel 2007 功能区上的标签值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26475692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com