Results 1 to 20 of 25

Thread: How does one activate ribbon components from an xlam file ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,887
    Location
    This is in the attached XLSM, but I saved it as an XLAM and it seems to work OK


    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnRibbonLoad" >
    <ribbon>
    <tabs>
    <tab id="CustomTab" label="My Tab">
      <group id="gMaster" label="Master Group">
      <toggleButton id="tbA"
       size="large"
       imageMso="A"
       getLabel="getToggleLabel"
       getPressed="getTogglePressed"
       onAction="onToggleAction"
       screentip = "This hides or shows Group A"
       />
      <toggleButton id="tbB"
       size="large"
       imageMso="B"
       getLabel="getToggleLabel"
       getPressed="getTogglePressed"
       onAction="onToggleAction"
       screentip = "This hides or shows Group B"
       />
      <toggleButton id="tbC"
       size="large"
       imageMso="C"
       getLabel="getToggleLabel"
       getPressed="getTogglePressed"
       onAction="onToggleAction"
       screentip = "This hides or shows Group C"
       />
     </group>
        
     <group id="gA" label="Group A" getVisible = "getGroupVisible">
      <button id="bA1" label="FirstA" size="large" onAction="actionButton" imageMso="HappyFace"/>
      <button id="bA2" label="SecondA" size="large" onAction="actionButton" imageMso="HappyFace" />
      <button id="bA3" label="ThirdA" size="large" onAction="actionButton" imageMso="HappyFace" />
     </group >
     <group id="gB" label="Group B"  getVisible = "getGroupVisible">
      <button id="bB1" label="FirstB" size="large" onAction="actionButton"  imageMso="HappyFace"/>
      <button id="bB2" label="SecondB" size="large" onAction="actionButton"  imageMso="HappyFace"/>
      <button id="bB3" label="ThirdB" size="large" onAction="actionButton"  imageMso="HappyFace"/>
     </group >
     <group id="gC" label="Group C"  getVisible = "getGroupVisible">
      <button id="bC1" label="FirstC" size="large" onAction="actionButton"  imageMso="HappyFace"/>
      <button id="bC2" label="SecondC" size="large" onAction="actionButton"  imageMso="HappyFace"/>
      <button id="bC3" label="ThirdC" size="large" onAction="actionButton"  imageMso="HappyFace"/>
     </group >
    </tab>
    </tabs>
    </ribbon>
    </customUI>


    and

    Option Explicit
    Public bVisibleA As Boolean, bVisibleB As Boolean, bVisibleC As Boolean
    Public bPressedA As Boolean, bPressedB As Boolean, bPressedC As Boolean
    Public oRibbon As IRibbonUI
     
    'Callback for customUI.onLoad
    Sub OnRibbonLoad(ribbon As IRibbonUI)
        Set oRibbon = ribbon
        
        bVisibleA = False
        bVisibleB = False
        bVisibleC = False
        bPressedA = False
        bPressedB = False
        bPressedC = False
     
    End Sub
    'Callback for tbA getLabel
    Sub getToggleLabel(control As IRibbonControl, ByRef returnedVal)
        Select Case control.ID
            Case "tbA"
                If bVisibleA Then
                    returnedVal = "Hide A"
                Else
                    returnedVal = "Show A"
                End If
            Case "tbB"
                If bVisibleB Then
                    returnedVal = "Hide B"
                Else
                    returnedVal = "Show B"
                End If
            Case "tbC"
                If bVisibleC Then
                    returnedVal = "Hide C"
                Else
                    returnedVal = "Show C"
                End If
        End Select
    End Sub
    'Callback for tbA getPressed
    Sub getTogglePressed(control As IRibbonControl, ByRef returnedVal)
        Select Case control.ID
            Case "tbA"
                returnedVal = bPressedA
            Case "tbB"
                returnedVal = bPressedB
            Case "tbC"
                returnedVal = bPressedC
        End Select
    End Sub
    'Callback for tbA onAction
    Sub onToggleAction(control As IRibbonControl, pressed As Boolean)
        
        Select Case control.ID
            Case "tbA"
                bPressedA = Not bPressedA
                bVisibleA = Not bVisibleA
                oRibbon.Invalidate
            Case "tbB"
                bPressedB = Not bPressedB
                bVisibleB = Not bVisibleB
                oRibbon.Invalidate
            Case "tbC"
                bPressedC = Not bPressedC
                bVisibleC = Not bVisibleC
                oRibbon.Invalidate
        End Select
    End Sub
    'Callback for gA getVisible
    Sub getGroupVisible(control As IRibbonControl, ByRef returnedVal)
        Select Case control.ID
            Case "gA"
                returnedVal = bVisibleA
            Case "gB"
                returnedVal = bVisibleB
            Case "gC"
                returnedVal = bVisibleC
        End Select
    End Sub
    'Callback for bA1 onAction
    Sub actionButton(control As IRibbonControl)
        MsgBox "You clicked " & control.ID
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •