Consulting

Results 1 to 3 of 3

Thread: Multiple problems with custom ribbon (loading images and re-loading)

  1. #1

    Multiple problems with custom ribbon (loading images and re-loading)

    Hi All,

    In a nut shell, I have multiple buttons in a custom ribbon (with multiple custom icons for each button) and would like the icon to be different depending on a cell value (different cell controlling each button).

    Therefore, I have used a callback to set the image to load for each button.

    However, (issues 1) I cant seem to get the image to load (VBA states "compile error: object required", see example VBA code below for btn1, same for btn2 just change 1 to 2). The "image" name line (after "Set") is exactly how I would write the xml code if the image was fixed (between image and the final ").

    Sub CallBackBtn1Img(control As IRibbonControl, ByRef image)
        Select Case control.ID
            Case "btn1"
            Select Case btn1enabled
                Case True: Set image = "_x0031_enabled"
                Case False: Set image = "_x0031_off"
            End Select
        End Select
    End Sub
    The full XML code for the example workbook is below (hide editing group to make space):

    <?xml version="1.0" encoding="utf-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_OnLoad">
     <ribbon>
      <tabs>
        <tab idMso="TabHome">
            <group idMso="GroupEditingExcel" visible="false"/>
            <group id="Buttons" label="Test Buttons">
                <button id="btn1" label="Test Button 1" getImage="CallBackBtn1Img"/>
                <button id="btn2" label="Test Button 2" getImage="CallBackBtn2Img"/>
            </group>
        </tab>
      </tabs>
     </ribbon>
    </customUI>
    Issue 2

    In the example workbook attached, I am changing the state (case) by pressing a button on the worksheet (instead of a cell value just to make it easier to do), but I cant work out how to get the ribbon to refresh (comes up with argument not options). Code for changing state of btn1 below (included line numbers to help me pin down problem, but it didn't help):

    Sub ChangeBtn1(control As IRibbonControl)
    
    
    On Error GoTo ErrorHandler
    
    
    
    
    10    If btn1enabled = True Then
    20        btn1enabled = False
    30    Else
    40        btn1enabled = True
    50    End If
        
    60    RefreshRibbon ("btn1")
        
        Exit Sub
    
    
    ErrorHandler:
    Debug.Print "Error # " & Str(Err.Number) & " was generated by line number: " & Erl
    
    
    End Sub
    I have scoured all of the code I could find from example workbooks by Ron de Bruin and Gregory Maxey, but just cant seem to work it out either of these problems.

    Ideally, I would like to load the images from within the file itself (without un-zipping the images into another folder).

    The example workbook attached shows what I have at the moment.

    Please can someone help.

    Thank you in advance

    Aman
    Attached Files Attached Files

  2. #2
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    337
    Location
    See attached.
    You will need to export the images as you can access them at run time whilst they are part of the file.

    If you don't want the images separate then you should be able to store the images in activex image controls and load direct from there although the image will probably not be a true PNG
    Or you could use the built in images.
    Attached Files Attached Files
    Cheers
    Andy

  3. #3
    Thank you, Andy.

    Very helpful.

    I didn't want to load form an external folder because the file may be emailed to someone to fill out. So I guess I have to change tack-tick and go for "getVisible" instead...

    Thank you again.

    Aman

Posting Permissions

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