Loading Custom Icons from FilesAs explained in the section on the FaceID setting above, each version of Excel from 2000 onward uses a slightly different UI drawing technique. This means custom icons stored as pictures on a worksheet will only appear correctly in the version of Excel in which they were optimized.For applications running under Excel 2002 or higher, there is a second way to apply custom icons to command bar controls that eliminates the problems associated with the different drawing techniques used by different versions of Excel. The command bar builder supports this method automatically, but in this section we will explain how to use it manually so you can take advantage of it in an application that does not use the command bar builder.Beginning with Office XP, two new properties were added to the CommandBarButton object. These two properties enable you to load icons directly into the control. The Picture property specifies the bitmap to be used as the foreground of the icon and the Mask property specifies the bitmap that indicates which areas of the icon should be rendered as transparent background. In the next section, we show you how to create these bitmaps.Chapter 20 Combining Excel and Visual Basic 6 we show how you can package up all of your custom icons into a single DLL resource file. Alternatively, if you are using the command bar builder, you can host both the icon and mask picture files on the wksCommandBars worksheet. Creating Bitmap Files for Icons and MasksIf you plan to create custom icons on a regular basis, it probably makes sense to purchase a special-purpose icon creation program. For the occasional custom icon, however, every version of Windows comes with a perfectly serviceable icon creation tool: Microsoft Paint.The type of file you will need to create for use as a CommandBarButton icon is a 16x16 pixel 16-color bitmap. The icon file will contain the artistic foreground picture you think of as your icon. The mask file is an overlay for the icon file in which everything foreground is colored black and everything you want to be transparent background is colored white.To create a custom icon, open Microsoft Paint. Paint will open with a blank default image canvas. Select Image > Attributes from the Paint menu. In the Attributes dialog, set Width and Height to 16, Units to Pixels and Colors to Color. These settings are shown in Figure 8-14. Figure 8-14. The Icon Attributes Settings![]() Figure 8-15. The Blank Icon Canvas in Paint![]() Figure 8-16. The Arrows Icon![]() Figure 8-17. The Mask File for the Arrows Icon![]() Using Bitmap Files as CommandBarButton IconsNow that we have our icon and mask bitmaps, it's a simple matter to apply them to a CommandBarButton. The procedures shown in Listing 8-7 build a command bar with a single button that uses our custom arrow icon and mask. You can find this code in the LoadPictureAndMask.xls workbook located on the CD in the \Concepts\Ch08Advanced Command Bar Handling folder. Note that this example only works in Excel 2002 or later. Listing 8-7. Adding a Custom Icon to a CommandBarButtonTo create the command bar button with the custom icon, run the CreateBar procedure. To remove the demo command bar and its button, run the RemoveBar procedure. The resulting custom icon appears as shown in Figure 8-18. Figure 8-18. The Arrows Custom Icon![]() ![]() |