Resting Anchor

The Anchorage

Personal website of Gregory K. Maxey, Commander USN (Retired)

Ribbon Images & Labels Part III
(A Microsoft Word Help & Tip page by Gregory K. Maxey)

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

Click to donate British Pound Sterling                   Click to donate US dollars                   Click to donate EU euros

This Microsoft Word Help & Microsoft Word Tips page is the third in a series of tips pages written to show how to apply and use the ribbon control attributes to define, modify and display control images and labels. See the Word Help & Tips Index for links to the other pages in this series.

In this tips page we will look at using the dynamic attribute getImage to load custom images from external sources.

The illustration below shows a custom ribbon tab that I created for this tips page. All of the controls perform some action.  You can download the demonstration document used to create this pages which contains the associated ribbon, custom XML and VBA callbacks using this link: Ribbon Images & Labels Part III

ribbon images and labels p3 1

LoadPicture Function

Group 1 contains six custom button controls and illustrates the simplest method of loading a custom image at runtime (or on the fly) using the built-in VBA LoadPicture function.

It also exposes an unfortunate shortcoming with that method. The built-in VBA LoadPicture function does not recognize PNG type images as valid picture types. The image defined in the VBA callback for Button 5 is a .PNG type file and can't be loaded using the LoadPicture VBA function. If you have already downloaded and opened the demonstration document then you have seen the VBA error message.

If you recall, PNG format is the type recommended for ribbon controls. See: Jensen Harris' RibbonX Image FAQ

Site Note IconNote: The image for Button 4 is the same image as the image for Button 6 but in a .bmp format. The image for Button 6 is a .PNG format file located in the document's zip data store "customUI\images" and applied using the image attribute. You should clearly see why .PNG format files are recommended for ribbon controls.

To overcome this shortcoming we need to move to a more advanced custom VBA function that utilizes the Windows GDI+ (Graphics Device Interface Plus) subsystem APIs (Application Programming Interfaces).

Site Note IconDon't worry. If this sounds like mumbo jumbo you are not alone. I couldn't offer a sound breakdown or technical explanation if I wanted too. Just think of it as a tool you use to achieve your goals. Like the computers we used to write or read this document,, we really don't have to understand everything about how or why it works.

The function we'll use is titled LoadPictureGDI. It is contained (with the GDI+ APIs) in the project module titled "Mod_LoadPictureGDI" in the demonstration document.

LoadPictureGDI Function

Group 2 contains two custom button controls with custom images loaded using the custom LoadPictureGDI function and illustrates that you can use the LoadPictrueGDI function to load all supported control image formats.

This concludes this tips page. You have now seen how to apply built-in images, images from customUI\images folder in the document's data store and images from external sources. In the next tips page, Ribbon Images & Labels Part IV, we will look at creating dynamic controls such as toggle button controls that take different images and labels "on the fly" depending on the toggle state.

Share

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

Click to donate British Pound Sterling                   Click to donate US dollars                   Click to donate EU euros

Search my site or the web using Google Search Engine

Google Search Logo