Consulting

Results 1 to 7 of 7

Thread: Ribbon Toggle Buttons Issue

  1. #1
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location

    Ribbon Toggle Buttons Issue

    Hi Folks

    I'm trying to add some "Custom Filtering" via toggle buttons in the ribbon. The idea is that there are 4 main sections (blocks) of columns, and i'd like to put 4 toggle buttons in the ribbon to hide or show the blocks/sections of interest, depending on what the user will toggle on/off; in the end to allow the user only print the relevant sections and to avoid a printout that's longer than the room lol

    For that, I've appended the ribbon images to the file (e.g. 1 with a color background for not toggled, and 1 with gray background for toggled; and that for each of the 4) using the CustomUI editor.

    <?xml version="1.0" encoding="utf-8"?>
    <customUI onLoad="subRibbonOnLoad" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon startFromScratch="false" >
    <tabs>
    <tab id="Allgemein" label="Allgemein" insertBeforeMso="TabHome" getVisible="subGetVisible" tag="wsAllg">
    <group id="Ansicht_Allg" label="Ansicht">
    <toggleButton id="Toggle_1_Allg" size="large" image="Icon_11" screentip="1 Managementfähigkeiten" onAction="subMatrixAnsicht" />
    <toggleButton id="Toggle_2_Allg" size="large" image="Icon_21" screentip="2 Fähigkeiten im Verhalten" onAction="subMatrixAnsicht" />
    <toggleButton id="Toggle_3_Allg" size="large" image="Icon_31" screentip="3 Fachkompentenz allgemein" onAction="subMatrixAnsicht" />
    <toggleButton id="Toggle_4_Allg" size="large" image="Icon_41" screentip="4 Fachkompetenzn anlagenspezifisch" onAction="subMatrixAnsicht" />
    </group>
    </tab>
    </tabs>
    </ribbon>
    </customUI>

    Now, the problem is to make these buttons useful. For each image, i've appended a greyed out version (e.g. Icon_11 in color and Icon_10 in grey background).

    So now, the first issue is to make the buttons respond to clicks and with that to change the images in question (i.e. color or grey).

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    1. The same image is used for a Toggled and a 'Not Toggled' state (unless you use GetImage). Just gets a gray background when it's 'Down'

    Capture.JPG


    2. To use the Toggle button you need to use the

    Sub GetPressed(control As IRibbonControl, ByRef returnedVal)
    
    and the 
    
    Sub OnToggle(control As IRibbonControl, pressed As Boolean)
    callbacks

    I could probably mock up a sample demo if you want
    Last edited by Paul_Hossler; 01-27-2019 at 04:55 PM.
    ---------------------------------------------------------------------------------------------------------------------

    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

  3. #3
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location
    Thank you Paul for your feedback,

    Sorry for beeing a novice; I've been able to use the callback concept for adding sheet-dependent custom tabs (using getVisible callbacks) but the getImage seems tricky

    It seems like file uploads are not possible anymore here?! So, I can just show you the VBE code and xml below:

    'Menüband laden (Callback für customUI.onLoad; wird beim Öffnen der Datei ausgeführt)Sub subRibbonOnLoad(ribbon As IRibbonUI)
    
    
        'Variablen dimensionieren/speichern
        Set rbnRib = ribbon
    
    
        If Not ObjPtr(ribbon) = 0 Then
            With wsHelfer
                .Unprotect
                .Range("B3").Value = ObjPtr(ribbon)
                .Protect
            End With
        End If
    
    
    End Sub
    
    
    'Menüband wechseln (Callback für CustomUI.subGetVisible; wird beim Blattwechsel ausgeführt)
    Sub subGetVisible(control As IRibbonControl, ByRef visible)
    
    
        If control.Tag = strRibbonTag Then
            visible = True
        Else
            visible = False
        End If
    
    
    End Sub
    
    
    'Callback for Toggle_1_Allg getPressed
    Sub subGetPressed(control As IRibbonControl, ByRef pressed)
    
    
        
    
    
    End Sub
    
    
    Sub subGetImage(imageID As String, ByRef image)
    
    
        Dim tabMenüBand As ListObject: Set tabMenüBand = wsHelfer.ListObjects("tabMenüBand")
        Dim strButton As String
        strButton = Mid(control.ID, InStr(1, control.ID, "_") + 1, Len(control.ID))
        strButton = Left(strButton, InStr(strButton, "_") - 1)
        
        If strButton = "0" Then
            image = "Icon_" & control.Tag & "0"
            image = "Icon_" & control.Tag & "1"
        End If
    
    
    End Sub
    
    
    'Menüband aktualisieren/neu zeichnen (Callback für CustomUI.invalidate; wird beim Öffnen/Blattwechsel ausgeführt)
    Sub subRefreshRibbon(Tag As String)
    
    
        'Variablen dimensionieren/speichern
        strRibbonTag = Tag
        
        If rbnRib Is Nothing Then
            If Not CStr(wsHelfer.Range("B3")) = "" Then
                Set rbnRib = fctgetribbon(wsHelfer.Range("B3").Value)
                rbnRib.Invalidate
            End If
        Else
            rbnRib.Invalidate
        End If
    
    
    End Sub
    
    
    'Pointer für zu ladendes Menüband ermitteln (i.e Speicherort des Menübandstatuses im Arbeitsspeicher)
    Function fctgetribbon(ByVal rbnPointer As LongPtr) As IRibbonUI
    
    
        CopyMemory rbnRib, rbnPointer, LenB(rbnPointer)
        Set fctgetribbon = rbnRib
    
    
    End Function
    <?xml version="1.0" encoding="utf-8"?>
    <customUI onLoad="subRibbonOnLoad" loadImage="subGetImage" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
      <ribbon startFromScratch="false" >
        <tabs>
          <tab id="Allgemein" label="Allgemein" insertBeforeMso="TabHome" getVisible="subGetVisible" tag="wsAllg">
            <group id="Ansicht_Allg" label="Ansicht">
    		<toggleButton id="Toggle_1_wsAllg" tag="1" size="large" getImage="subGetImage" screentip="1 Managementfähigkeiten" getPressed="subGetPressed" />
    		<toggleButton id="Toggle_2_wsAllg" tag="2" size="large" getImage="subGetImage" screentip="2 Fähigkeiten im Verhalten" getPressed="subGetPressed" />
    		<toggleButton id="Toggle_3_wsAllg" tag="3" size="large" getImage="subGetImage" screentip="3 Fachkompetenz allgemein" getPressed="subGetPressed" />
    		<toggleButton id="Toggle_4_wsAllg" tag="4" size="large" getImage="subGetImage" screentip="4 Fachkompetenz anlagenspezifisch" getPressed="subGetPressed" />
    		<toggleButton id="Toggle_5_wsAllg" tag="L1" size="large" getImage="subGetImage" screentip="Level 1 Kompetenzen" getPressed="subGetPressed" />
    		<toggleButton id="Toggle_6_wsAllg" tag="L2" size="large" getImage="subGetImage" screentip="Level 2 Themen" getPressed="subGetPressed" />
    		<toggleButton id="Toggle_7_wsAllg" tag="L3" size="large" getImage="subGetImage" screentip="Level 3 Trainings" getPressed="subGetPressed" />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    You should be able to attach a file.

    [Go Advanced] at lower right, then click the paperclip icon
    ---------------------------------------------------------------------------------------------------------------------

    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

  5. #5
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location
    That doesn't work...I get an error message each time. Tried to zip the excel file, but then the error is that it's larger than 1MB (1! WTF)

  6. #6
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location
    Why did they make this that complicated, I mean the RibbonX and the callbacks. And then there hardly any documentation available as it seems.

    So, I've got the following attributes in the XML CustomUI
    - onLoad (on openening the workbook, great)
    - loadImage (no Idea if that makes sense)
    - getVisible (each time I open/switch a worksheet, great)

    And then
    - getImage (it never seems to be called)
    - getPressed (it never seems to be called)
    - onAction (this is the only one being called) when pressing a button

    Obviously I'm not getting the concept right (

    Maybe some example files could help a lot

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    If I remember correctly, getImage callback will only return a built in (mso) image

    Here's a sample file with only two toggle buttons that I think shows the concepts for what you want to do
    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
  •