0
votes

Images in the office ribbon can be large (32x32) or small (16x16). If they are specified as large, but the window is too narrow to fit them, then they are automatically made small. By default, these are just a condensed version of the larger image.

There was an office design document (since disappeared) that suggested that one should properly design the small icons, and that they should not just be small versions of the big ones because condensing to 16x16 does not always work very well. Very sensible.

But does one actually do it in the XML? Elements like Button only seem to have one image attribute. I would expect two, largeImage and smallImage (say).

Is this something that really needs horrible call backs? In which case, how does one catch the event that the ribbon has decided to resize the image? (Ribbon call backs are a mess with VBA for several reasons.)

1

1 Answers

2
votes

The Ribbon XML does not have an option to specify large and small icons as part of its defintion. If you use the image attribute then you can provide only one picture.

There's also no way to catch whether/when Office reduces the size of the Ribbon. You'd have to do some research, checking which window width triggers the resize, then you could use the WindowResize event of the Application object to invalidate the control(s), changing the picture (and possibly the control size).

In order to provide more than one icon you'd need to use the callback attribute getImage to tell the Ribbon which picture to use. This isn't as simple as passing the string value of a file stored in the Office document as the callback function expects an IPictureDisp object; the image would need to be stored outside the Office document, as a file.

The intricacies of using getImage are described in Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3), near the end of the article, but the code provided there is for the .NET Framework.

It's actually a bit easier to code using VBA since the stdOle library that provides IPictureDisp is an office library. You need to set a reference to the library - in the VBA Editor's Tools/References it's labelled as OLE Automation. Note that this does not work with the graphic png file format - the library is a bit old...

Public Sub GetIconImage(control As IRibbonControl, ByRef image)     
  Dim sPicPath As String
  Dim stdPic As StdPicture

  sPicPath = "C:\Users\[userName]\Pictures\test.jpg"  'Schweiz.png"
  Set stdPic = stdole.StdFunctions.LoadPicture(sPicPath)
  Set image = stdPic
End Sub