Excel 功能区切换按钮不是 运行 onAction 或 getPressed 回调
Excel Ribbon Toggle Button not running onAction or getPressed callbacks
我已经通过 Excel.CustomUI 文件向功能区添加了一个切换按钮,这很好,但它实际上不会触发任何回调函数。我尝试了网上给出的各种组合,但根本无法获得 运行 的任何功能。
我也试过使用复选框,但这也没有 运行 功能。我检查并删除了所有安全措施,但无济于事。
我有按要求工作的标准按钮。
我遗漏了什么?
这是 excel.customUI 文件
<mso:customUI xmlns:mso='http://schemas.microsoft.com/office/2009/07/customui'
onLoad='ToggleAutoCalc' >
<mso:ribbon>
<mso:qat/>
<mso:tabs>
<mso:tab id='reportTab' label='ICit' insertBeforeQ='mso:TabFormat'>
<mso:group id='reportGroup' label='DBRW Copy Paste' autoScale='true'>
<mso:button id='DBRW Copy' label='DBRW Copy'
imageMso='Copy' onAction='DBRWCopyPaste.xlam!TM1Copy'/>
<mso:button id='DBRW Paste' label='DBRW Paste'
imageMso='Paste' onAction='DBRWCopyPaste.xlam!TM1Paste'/>
<mso:button id='DBRW UnDo' label='DBRW UnDo'
imageMso='CellsDelete' onAction='DBRWCopyPaste.xlam!TM1UndoPaste'/>
**<mso:toggleButton id='AutoCalc' label='AutoCalc'
screentip='Toggle Autocalc'
size='Large'
imageMso='ColumnSettingsMenu' onAction='DBRWCopyPaste.xlam!TbtnToggleAutoCalc'
getPressed='DBRWCopyPaste.xlam!GetPressed'/>**
</mso:group>
</mso:tab>
</mso:tabs>
</mso:ribbon>
</mso:customUI>
这是我的测试VBA代码:
Option Explicit
Public MyRibbon As IRibbonUI
Sub ToggleAutoCalc(ribbon As IRibbonUI)
Set MyRibbon = ribbon
Debug.Print "ToggleAutoCalc"
End Sub
Sub TbtnToggleAutoCalc(control As IRibbonControl, pressed As Boolean)
pressed = True
End Sub
Sub GetPressed(control As IRibbonControl, ByRef returnedVal)
Dim bAutoCalc As Integer
Dim sVal As String
Dim nVal As Integer
GetPressed = returnedVal
End Sub
单引号应该是你XML中的双引号。此外,id 标签不允许名称包含 space。
您是否使用自定义 UI 编辑器来编辑您的 XML?该工具中有一项功能可以检查您的 XML 是否格式正确。这是一个 link https://www.rondebruin.nl/win/s2/win001.htm
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="ToggleAutoCalc">
<ribbon>
<tabs>
<tab
id="reportTab"
label="ICit"
insertBeforeQ="TabFormat"
>
<group
id="reportGroup"
label="DBRW Copy Paste"
autoScale="true"
>
<button
id="DBRW_Copy"
label="DBRW Copy"
imageMso="Copy"
onAction="TM1Copy"
/>
<button
id="DBRW_Paste"
label="DBRW Paste"
imageMso="Paste"
onAction="TM1Paste"
/>
<button
id="DBRW_UnDo"
label="DBRW UnDo"
imageMso="CellsDelete"
onAction="TM1UndoPaste"
/>
<toggleButton
id="AutoCalc"
label="AutoCalc"
screentip="Toggle Autocalc"
size="large"
imageMso="ColumnSettingsMenu"
onAction="OnAction"
getPressed="GetPressed"
/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
在你的 VBA 中,首先创建一个全局变量,如 "IsPressed"。
那么 "GetPressed" 程序应该使用 "returnedVal" 变量来 return 值。
Option Explicit
Public MyRibbon As IRibbonUI
Public IsPressed As Boolean
Sub ToggleAutoCalc(ribbon As IRibbonUI)
Set MyRibbon = ribbon
End Sub
Sub GetPressed(control As IRibbonControl, ByRef returnedVal)
Select Case control.ID
Case "AutoCalc"
returnedVal = IsPressed
End Select
End Sub
Sub OnAction(control As IRibbonControl, pressed As Boolean)
Select Case control.ID
Case "AutoCalc"
IsPressed = pressed
If IsPressed Then
MsgBox IsPressed
Else
MsgBox IsPressed
End If
End Select
End Sub
我已经通过 Excel.CustomUI 文件向功能区添加了一个切换按钮,这很好,但它实际上不会触发任何回调函数。我尝试了网上给出的各种组合,但根本无法获得 运行 的任何功能。
我也试过使用复选框,但这也没有 运行 功能。我检查并删除了所有安全措施,但无济于事。
我有按要求工作的标准按钮。
我遗漏了什么?
这是 excel.customUI 文件
<mso:customUI xmlns:mso='http://schemas.microsoft.com/office/2009/07/customui'
onLoad='ToggleAutoCalc' >
<mso:ribbon>
<mso:qat/>
<mso:tabs>
<mso:tab id='reportTab' label='ICit' insertBeforeQ='mso:TabFormat'>
<mso:group id='reportGroup' label='DBRW Copy Paste' autoScale='true'>
<mso:button id='DBRW Copy' label='DBRW Copy'
imageMso='Copy' onAction='DBRWCopyPaste.xlam!TM1Copy'/>
<mso:button id='DBRW Paste' label='DBRW Paste'
imageMso='Paste' onAction='DBRWCopyPaste.xlam!TM1Paste'/>
<mso:button id='DBRW UnDo' label='DBRW UnDo'
imageMso='CellsDelete' onAction='DBRWCopyPaste.xlam!TM1UndoPaste'/>
**<mso:toggleButton id='AutoCalc' label='AutoCalc'
screentip='Toggle Autocalc'
size='Large'
imageMso='ColumnSettingsMenu' onAction='DBRWCopyPaste.xlam!TbtnToggleAutoCalc'
getPressed='DBRWCopyPaste.xlam!GetPressed'/>**
</mso:group>
</mso:tab>
</mso:tabs>
</mso:ribbon>
</mso:customUI>
这是我的测试VBA代码:
Option Explicit
Public MyRibbon As IRibbonUI
Sub ToggleAutoCalc(ribbon As IRibbonUI)
Set MyRibbon = ribbon
Debug.Print "ToggleAutoCalc"
End Sub
Sub TbtnToggleAutoCalc(control As IRibbonControl, pressed As Boolean)
pressed = True
End Sub
Sub GetPressed(control As IRibbonControl, ByRef returnedVal)
Dim bAutoCalc As Integer
Dim sVal As String
Dim nVal As Integer
GetPressed = returnedVal
End Sub
单引号应该是你XML中的双引号。此外,id 标签不允许名称包含 space。
您是否使用自定义 UI 编辑器来编辑您的 XML?该工具中有一项功能可以检查您的 XML 是否格式正确。这是一个 link https://www.rondebruin.nl/win/s2/win001.htm
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="ToggleAutoCalc">
<ribbon>
<tabs>
<tab
id="reportTab"
label="ICit"
insertBeforeQ="TabFormat"
>
<group
id="reportGroup"
label="DBRW Copy Paste"
autoScale="true"
>
<button
id="DBRW_Copy"
label="DBRW Copy"
imageMso="Copy"
onAction="TM1Copy"
/>
<button
id="DBRW_Paste"
label="DBRW Paste"
imageMso="Paste"
onAction="TM1Paste"
/>
<button
id="DBRW_UnDo"
label="DBRW UnDo"
imageMso="CellsDelete"
onAction="TM1UndoPaste"
/>
<toggleButton
id="AutoCalc"
label="AutoCalc"
screentip="Toggle Autocalc"
size="large"
imageMso="ColumnSettingsMenu"
onAction="OnAction"
getPressed="GetPressed"
/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
在你的 VBA 中,首先创建一个全局变量,如 "IsPressed"。
那么 "GetPressed" 程序应该使用 "returnedVal" 变量来 return 值。
Option Explicit
Public MyRibbon As IRibbonUI
Public IsPressed As Boolean
Sub ToggleAutoCalc(ribbon As IRibbonUI)
Set MyRibbon = ribbon
End Sub
Sub GetPressed(control As IRibbonControl, ByRef returnedVal)
Select Case control.ID
Case "AutoCalc"
returnedVal = IsPressed
End Select
End Sub
Sub OnAction(control As IRibbonControl, pressed As Boolean)
Select Case control.ID
Case "AutoCalc"
IsPressed = pressed
If IsPressed Then
MsgBox IsPressed
Else
MsgBox IsPressed
End If
End Select
End Sub