在VBA中将复选框添加到自定义功能区



我需要帮助在自定义Excel功能区中添加一个复选框,该复选框允许我在单击某个函数时运行该函数。我可以让复选框出现,但单击时它什么也不做。我需要提供类似于此示例的东西,但它需要在最新版本的Excel365上工作。https://spreadsheetgurucourses.com/checkbox-control/#

<customUI onLoad="RibbonLoaded_myAddin" xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab id="MyCoolAddin" label="My Cool Addin">
<group id="GroupA" label="Checkbox Example">
<checkBox
id="Checkbox01"
label="Display Gridlines"
getPressed="checkbox01_startup"
onAction="checkbox01_clicked"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

您需要在VBA中实现回调。。。对于上面的RibbonXML,您需要在标准模块中使用这三个:

Sub RibbonLoaded_myAddin(ribbon As IRibbonUI)
End Sub
Sub checkbox01_startup(control As IRibbonControl, ByRef returnedVal)
End Sub
Sub checkbox01_clicked(control As IRibbonControl, pressed As Boolean)
If pressed Then
MsgBox "I'm checked"
Else
MsgBox "I'm cleared"
End If
End Sub

根据你想要达到的目标,你可能不需要前两个。然后将代码添加到checkbox01_clicked中,以便在选中/清除复选框时进行操作。

最新更新