Consulting

Results 1 to 20 of 33

Thread: Ribbon - toggle button problems

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,748
    Location
    You just need to use the getPressed callback and to include onLoad in your xmlns

    Option Explicit
    Public gobjRibbon As IRibbonUI
    Public B1 As Boolean, B2 As Boolean
     
    Public Sub OnRibbonLoad(objRibbon As IRibbonUI)
    Set gobjRibbon = objRibbon
    B1 = False
    B2 = False
    End Sub
     
    'Callback for customButton1 onAction
    Sub Pushed(control As IRibbonControl, pressed As Boolean)
    Select Case control.ID
        Case "customButton1"
            B1 = True
            B2 = False
        Case "customButton2"
            B1 = False
            B2 = True
    End Select
    gobjRibbon.Invalidate
    End Sub
    
    'Callback for customButton1 getPressed
    Sub UpOrDown(control As IRibbonControl, ByRef returnedVal)
    Select Case control.ID
        Case "customButton1"
            returnedVal = B1
        Case "customButton2"
            returnedVal = B2
    End Select
    End Sub
     
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"onLoad="OnRibbonLoad" >
    <ribbon startFromScratch="false">
    <tabs>
    <tab id="customTab"label="Custom Tab">
    <group id="customGroup"label="Custom Group">
    <toggleButton id="customButton1"label="Face 1"imageMso="HappyFace"size="large"onAction="Pushed"getPressed="UpOrDown" />
    <toggleButton id="customButton2"label="Face 2"imageMso="HappyFace"size="large"onAction="Pushed"getPressed="UpOrDown" />
    </group>
    </tab>
    </tabs>
    </ribbon>
    </customUI> 
    
    Paul
    Attached Files Attached Files
    Last edited by Aussiebear; 04-25-2023 at 07:16 PM. Reason: Adjusted the code tags

  2. #2
    Hi Paul,
    This may be outdated but just came across your solution for toggle buttons in ribbon. while it works for 2 buttons i would like it to work for 3 buttons i.e. one of the 3 button should be in pressed state. I am not a pro at vba but i tried to copy the code as in the attached file but does not work. Can you help me make it work please. I am using excel 2007.
    basically i want one toggle button to choose either one of the three currencies i.e. USD, EURO, GBP
    I have to use toggle button as i believe we cannot use option (radio) button in excel 2007 ribbon, which i would have loved to use instead.

    Thanks in advance
    Attached Files Attached Files

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    Quote Originally Posted by nischalshety View Post
    Hi Paul,
    This may be outdated but just came across your solution for toggle buttons in ribbon. while it works for 2 buttons i would like it to work for 3 buttons i.e. one of the 3 button should be in pressed state. I am not a pro at vba but i tried to copy the code as in the attached file but does not work. Can you help me make it work please. I am using excel 2007.
    basically i want one toggle button to choose either one of the three currencies i.e. USD, EURO, GBP
    I have to use toggle button as i believe we cannot use option (radio) button in excel 2007 ribbon, which i would have loved to use instead.
    I have a query that uses those same 3 currency options; I use a dropdown.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Thanks xld for your post, yes drop down can also be done, but i will be using the three toggle buttons also for other codes apart from currencies, like measurements or maybe to get data for different locations. here the dropdown can work but large toggle buttons if feel can be more useful for my purpose.

    Apreciate your feed back though...

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,748
    Location
    Quote Originally Posted by nischalshety View Post
    Hi Paul,
    This may be outdated but just came across your solution for toggle buttons in ribbon. while it works for 2 buttons i would like it to work for 3 buttons i.e. one of the 3 button should be in pressed state. I am not a pro at vba but i tried to copy the code as in the attached file but does not work. Can you help me make it work please. I am using excel 2007.
    basically i want one toggle button to choose either one of the three currencies i.e. USD, EURO, GBP
    I have to use toggle button as i believe we cannot use option (radio) button in excel 2007 ribbon, which i would have loved to use instead.

    Thanks in advance
    One way - you can see the XML and the Callback in the xlsm

    Capture.JPG
    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

  6. #6
    Paul, thats what i wanted, as i said i am really new to coding in VBA or XMLs i will surely study your code and try to make necessary changes to suit my requirement.
    Appreciate such a quick response buddy
    Stay healthy and merry xmas to you

  7. #7
    Please i would like to put a color on the ToggleButton of a ribbon when pressed.

Posting Permissions

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