Personal website of Gregory K. Maxey, Commander USN (Retired)
Do you have ad-blocking software enabled? While I respect your right to do so, your donations and the minimal advertisements on this site help to defray internet and other costs of providing this content. Please consider excluding this website from blocking or turning off the blocker while browsing this site.
The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.
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!
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
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
Note: 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).
Don'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.
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.
Do you want to make a payment for consulting work or donate to help support this site?
PayPal is a safe, easy way to pay online.
Use the appropriate currency "Donate" button to make a payment or donation.