top of page
John

Add an icon to a UserForm's title bar

Updated: Jul 29, 2022

Adding an icon to a UserForm's title bar can help to give a professional look to your UserForm.


The source icon must be a .ico file. If the image file you want to use is not a .ico file then you can use one of a number of online image converters to convert it from .jpg or .png etc to .ico ... search along the lines of "convert to icon file". Once you have your .ico file:

1. Add a UserForm to your VBA Project


2. Add an Image control to the UserForm and change its Name property to "ImageForIcon" (without the speech marks) ... you can actually use any name but this is the name I use in the SetIconFromImageControl procedure, below


3. Add the icon to the Image control ... in the UserForm designer, select the Image control. In the Properties window, click in the Picture property then click the box with the 3 dots and find your icon file (remember, it must be a .ico file)


4. So that the Image control is not visible at runtime, change its Visible property to False ... optionally drag the Image control right out to the right/bottom edge so it is not interfering with the other work you need to do in the UserForm designer


5. In the UserForm's code, in the declarations area, add the following Windows API calls and associated constants



6. And in the UserForm's code area below the declarations, add the SetIconFromImageControl procedure



7. And from the UserForm_Initialize event, call the SetIconFromImageControl procedure



8. That's it. The only thing left to do is to display the UserForm (in this example called UserForm1) from a standard code module eg



You can now delete the .ico file if you wish - as the file is stored in the Image control then the .ico file itself is no longer needed. Run your code and marvel at the icon. Here's an example:


UserForm with icon

0 comments

Comments


bottom of page