这是一个在横向和纵向之间切换的切换按钮。
如何构建它以始终“显示”活动工作表的状态?
getSelectedItemIndex
-回调不可用于toggleButton:
' -- XML
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="LoadRibbon">
<ribbon>
<tabs>
<tab id="Tabv3.1" label="TOOLS" insertAfterMso="TabHome">
<group id="Group6" label="Views">
<toggleButton id="ToggleButton01"
label="Orientation"
imageMso="PageOrientationLandscape"
size="large"
getPressed="ToggleButton01_Startup"
onAction="ToggleButton01_OnAction"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
' -- Standard Module
Option Explicit
Public RibUI As IRibbonUI
Sub LoadRibbon(Ribbon As IRibbonUI)
Set RibUI = Ribbon
End Sub
' ToggleButton 01 Startup
Sub ToggleButton01_Startup( _
ByRef control As IRibbonControl, _
ByRef returnedVal)
If ActiveSheet.PageSetup.Orientation = xlLandscape Then
returnedVal = xlLandscape
Else
returnedVal = xlPortrait
End If
End Sub
' ToggleButton 01 Click
Sub ToggleButton01_OnAction( _
ByRef control As IRibbonControl, _
ByRef pressed As Boolean)
Select Case pressed
Case True
ActiveSheet.PageSetup.Orientation = xlLandscape
Case False
ActiveSheet.PageSetup.Orientation = xlPortrait
End Select
End Sub
' -- ThisWorkbook
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
RibUI.InvalidateControl ("ToggleButton01")
End Sub
returnedVal
应该是 True
或 False
' ToggleButton 01 Startup
Sub ToggleButton01_Startup( _
ByRef control As IRibbonControl, _
ByRef returnedVal)
If ActiveSheet.PageSetup.Orientation = xlLandscape Then
returnedVal = True ' xlLandscape
Else
returnedVal = False 'xlPortrait
End If
End Sub