Excel 功能区切换按钮:页面方向横向 - 始终显示当前工作表的状态

问题描述 投票:0回答:1

这是一个切换按钮,用于在横向和纵向之间切换。

如何构建它以始终“显示”活动工作表的状态?

getSelectedItemIndex
-回调不可用于toggleButton:

https://learn.microsoft.com/en-us/openspecs/office_standards/ms-customui/ec42bfd0-149c-495b-895c-3bc708b8a149

' -- 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
excel vba togglebutton ribbonx
1个回答
1
投票
  • returnedVal
    应该是
    True
    False
' ToggleButton 01 Startup
Sub ToggleButton01_Startup( _
   ByRef control As IRibbonControl, _
   ByRef returnedVal)
   returnedVal = (ActiveSheet.PageSetup.Orientation = xlLandscape)
   'If ActiveSheet.PageSetup.Orientation = xlLandscape Then
   '     returnedVal = True ' xlLandscape
   'Else
   '     returnedVal = False 'xlPortrait
   'End If
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.