The quotes around the first word should alert the reader that this is not about actually animating a ribbon image but rather about simulating the effect.
The end effect of the experimentation described in this proof-of-concept note is the alternating image for the Custom Italic button

and

A few days ago I was developing a 2007 interface for some add-in. After trying out a few icons, it became apparent that an animated GIF (called AGIF below) would be the most effective way to convey some of the features of the add-in. I vaguely remembered some discussion at the last MVP summit that RibbonX did not support AGIFs. But, hoping I was wrong, my first attempt was to just that. I put one together (nothing fancy, just two images that alternated ad infinitum), created an empty workbook, saved it as a XLSM file, and opened it in the Office 2007 Custom UI Editor.
In the editor, I used one of the sample templates (Excel – A Custom Tab) to create a test ribbon. For one of the buttons (id=”customButton1?), I set the image attribute to the name of the AGIF, inserted the image file into the XLSM, saved the file, and opened it in Excel. Unfortunately, there was nothing wrong with my recollection. The ribbon did not animate the AGIF.
So, I figured that was that…until a day or so later when I was boarding a plane at some unearthly hour. Just as I got to my seat, I couldn’t help but think, “Duh! If you must, use code to swap the images!” While it wouldn’t be true animation (no custom transition effects) and it would require VBA code running on a timed basis, it might work in the right circumstances.
So, thoughts of sleep forgotten, I pulled out the laptop as soon as we climbed above 10,000 feet. Opening the XLSM file, I used one of the other buttons to specify the attribute getImage=”getImage”
<button id=”customButton1? label=”ConBold” size=”large” onaction=”conBoldSub” image=”animate”/>
<button id=”customButton2? label=”ConItalic” size=”large” onaction=”conItalicSub” getimage=”getImage”/>
Of course, now I had to write some code to provide RibbonX with the image at the appropriate time and also invalidate the control after so-many-seconds. The invalidation would cause RibbonX to ask for the image again, and this time the code would provide a different image.
The code below contains three logical segments.
The first initializes the myRibbon variable.
The second provides RibbonX with the image of choice. Since I had two images, named animate-1.gif and animate-2.gif, the code alternates between the two.
The third section is the timing controller. For the test, I used a 5 second delay with the application’s OnTime method. So, every 5 seconds the code invalidates the CustomButton2 control, which causes RibbonX to call the getImage procedure, which, in turn, returns the next image in the rotating sequence.
Option Explicit
Dim myRibbon As IRibbonUI
Dim LastNbr As Integer, NextTime As Date
‘Callback for customUI.onLoad
Sub RibbonLoaded(ribbon As IRibbonUI)
Set myRibbon = ribbon
FiveSecsAnimate
End Sub
‘Callback for customButton2 getImage
Sub getImage(control As IRibbonControl, ByRef returnedVal)
If LastNbr = 0 Then LastNbr = 1 Else LastNbr = LastNbr Mod 2 + 1
Set returnedVal = LoadPicture( _
ThisWorkbook.Path & Application.PathSeparator & ”animate-” & LastNbr & ”.gif”)
End Sub
Sub FiveSecsAnimate()
myRibbon.InvalidateControl ”customButton2″
NextTime = Now + TimeValue(“0:0:5″)
Application.OnTime NextTime, ”FiveSecsAnimate”
End Sub
Sub stopAnimation()
Application.OnTime NextTime, ”FiveSecsAnimate”, , False
End Sub
For the test I used images in the same directory as the workbook.
In conclusion, ideally the images should be in the workbook itself. The code would then refer to those images. But, I don’t know enough about how to refer to images in an Office2007 file or how to get LoadPicture to work with those images. While the best solution would be for Ribbon/RibbonX to support animated GIFs, the above is an alternative for those who cannot wait for Microsoft to get around to it.