0% found this document useful (0 votes)
1K views

Creating Modern-Looking Userform Controls in VBA

The document discusses how to create more modern-looking userforms in VBA by changing default properties and using alternative controls. It provides an example of replacing a checkbox with images of switches by positioning the images over the checkbox and changing their visibility based on the checkbox's value. More control alternatives are planned to be added.

Uploaded by

Anay Karambelkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Creating Modern-Looking Userform Controls in VBA

The document discusses how to create more modern-looking userforms in VBA by changing default properties and using alternative controls. It provides an example of replacing a checkbox with images of switches by positioning the images over the checkbox and changing their visibility based on the checkbox's value. More control alternatives are planned to be added.

Uploaded by

Anay Karambelkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

4/3/23, 3:38 PM Creating modern-looking userform controls in VBA

Site search
Search.. ?

Home Products ▼ Services ▼ Downloads ▼ Article index ▼ Links ▼

Contact ▼ Newsletter

Home > Article index > Modern Userform

Creating Modern-Looking Userforms In VBA

Content

Introduction

The example file

Default Userform properties

Modern looking controls

More to follow

Introduction
The Microsoft VBA editor was designed somewhere around 1996. This means that the standard
design of the userforms you create with that editor look really old-school if you don't do
anything. Here I show how we might create a more modern-looking user-interface by changing
some properties of the form and by using some tricks.

The example file


Download the file which contains both the old-school userform and the modern form.

Default userform properties


When you insert a new userform into your VBA project, the form is set to default properties:

https://jkp-ads.com/Articles/excel-modern-userform.asp 1/10
4/3/23, 3:38 PM Creating modern-looking userform controls in VBA

The default settings of a userform are used as a template for any new control you add
to it, so you can save yourself a lot of time by making the right choices right away.

Here are the settings I use to make my forms look more modern:

https://jkp-ads.com/Articles/excel-modern-userform.asp 2/10
4/3/23, 3:38 PM Creating modern-looking userform controls in VBA

The properties I change are:

Backcolor
I set that to Window Background (which is usually white) rather than the stale grey we
normally get

BorderStyle
Set to 0 - BorderStyleNone (this makes things like checkboxes and listboxes flat rather
than that old-school 3D effect)

Font
I change that to Calibri, just because I like that better than the default Tahoma. Calibri
turns out slightly smaller than Tahoma, which is why I set the size to 9 rather than 8.

ForeColor
I set that to the darkest grey there is on the pallette (just because I find Black is too

https://jkp-ads.com/Articles/excel-modern-userform.asp 3/10
4/3/23, 3:38 PM Creating modern-looking userform controls in VBA

black):

Modern looking controls

Checkbox alternative

This is the standard look of a userform with a checkbox:

Boring!

Let's see if we can improve on that:

See? That is better. So how did I create this?

1. From the Insert tab of Excel, choose Insert Icon:

https://jkp-ads.com/Articles/excel-modern-userform.asp 4/10
4/3/23, 3:38 PM Creating modern-looking userform controls in VBA

2. In the subsequent window, type "switch" in the search box, this is what I got:

3. I selected both icons and clicked Insert, giving me this:

4. I don't like the black. Let's change that. Right-click either of the icons and choose
"Convert to shape"

5. This ensures the icon is converted to a grouped set of built-in shapes, which are easy to
adjust. I did not change the selection, instead, I clicked the Shape Format contextual tab:

https://jkp-ads.com/Articles/excel-modern-userform.asp 5/10
4/3/23, 3:38 PM Creating modern-looking userform controls in VBA

6. I changed both Shape Fill and Shape Outline to green


7. I repeated steps 4 to 6 for the black (filled) switch
8. I dragged a checkbox control on my form (used a slightly larger Font size of 14)

9. Next I added an Image control, set its border to be hidden and the backcolor and
BorderColor to Window background, BorderStyle to 0 - BorderStyleNone:

https://jkp-ads.com/Articles/excel-modern-userform.asp 6/10
4/3/23, 3:38 PM Creating modern-looking userform controls in VBA

10. I then copied one of the switches by right-clicking them on the worksheet and choosing
Copy, clicked inside the Picture property and pressed control+v:

11. I changed the name of both Image controls, respectively to SwitchOn and SwitchOff and
placed them on top of each other, right on top of where the checkbox is:

12. To make things easier (Thanks Andy Pope, for the suggestion in the comments), set the
Enabled property of both switches to False. That way, you appear to click the image, but
the click will "go" to the checkbox control underneath, which is what we want.
13. Finally, we need some VBA code to make it look like we're moving the switch when we
click on the images and when we click on the text of the check box (I did not change the
name of the check box, so that is CheckBox1).
https://jkp-ads.com/Articles/excel-modern-userform.asp 7/10
4/3/23, 3:38 PM Creating modern-looking userform controls in VBA

We do not need the Image control events, as everything is handled from teh click on the
checkbox. Here is the VBA code we need to make this work:

Option Explicit
' ******Events******
Private Sub CheckBox1_Click()
SetSwitchInCorrectPosition
End Sub

Private Sub UserForm_Initialize()


SetSwitchInCorrectPosition
End Sub

' ******Private routines******


Private Sub SetSwitchInCorrectPosition()
If CheckBox1.Value Then
SwitchOn.Visible = True
SwitchOff.Visible = False
Else
SwitchOn.Visible = False
SwitchOff.Visible = True
End If
End Sub

Of course things become more complicated if you have multiple checkboxes on the form that
you want to work this way. I've implemented that in the multiple checkboxes example (in the
dowload) using two class modules.

More to follow
I've only discussed how you might create a nice-looking alternative for the check-box. I plan to
add more controls in the near future. If you've designed modern-looking alternatives yourself,
why not add your examples in the comments below?

Comments
Showing last 8 comments of 12 in total (Show All Comments):

Comment by: Jan Karel Pieterse (24-5-2022 10:08:00) deeplink to this comment

Hi Thiago,

Not sure what you mean, but doesn't it work if you place all controls inside the frame? If
needed duplicate the switches?

Comment by: Thiago (25-5-2022 05:17:00) deeplink to this comment

Sorry, I used Google Translate, it must have been a bit confusing. I'll try to explain it another
way. I did like this:

- I downloaded the example file;


- I used the example of the ModernMultiple form;
- In this form, I added a frame;
- Inside this frame, I put the checkbox.
- When clicking on the checkbox, the image is outside the frame.

https://jkp-ads.com/Articles/excel-modern-userform.asp 8/10
4/3/23, 3:38 PM Creating modern-looking userform controls in VBA

I send you the recording of my screen, I believe it will be easier to understand:


https://drive.google.com/file/d/1F32iFNKLUH6YJ2dxTftvu-kKLcchESBu/view?usp=sharing

Comment by: Jan Karel Pieterse (25-5-2022 10:37:00) deeplink to this comment

Hi Thiago,

Aha, I understand. I have updated the example file and it now also works with checkboxes in a
frame. I only had to change two lines of code in the class module clsChecks. So if you used the
idea in your own project, simply copy the clsChecks code and paste it in your own class
module.

Comment by: Thiago (26-5-2022 02:09:00) deeplink to this comment

Hi Jam,

Thanks a lot for the help, it worked perfectly here :)

Comment by: Ryder (25-10-2022 23:50:00) deeplink to this comment

Using office 2019... no "switch" in icons, sadly...


perhaps I'm doing it wrong?

Comment by: Jan Karel Pieterse (26-10-2022 09:50:00) deeplink to this comment

Hi Ryder,

I'm afraid the insert Icon feature is unavailable in Excel 2019.

Comment by: reza (28-12-2022 12:05:00) deeplink to this comment

Office v2019 Version 2211 (Build 1583120208) Updated December 13 already has the "insert
icon" feature.

Comment by: Rahib (18-3-2023 11:18:00) deeplink to this comment

Hi Jan

The idea is good, but to simplify it, what I did, I just wrote a code that when one picture is
clicked, that picture becomes invisible and the other picture becomes visible, and vice versa.
So, I dont have to deal with checkbox. and on my command button, the code is:

If Image1.Visibility = True
'do something
Else
'do other thing
End If

Have a question, comment or suggestion? Then please use this form.

If your question is not directly related to this web page, but rather a more general "How do I
do this" Excel question, then I advise you to ask your question here: www.eileenslounge.com.

https://jkp-ads.com/Articles/excel-modern-userform.asp 9/10
4/3/23, 3:38 PM Creating modern-looking userform controls in VBA

Please enter your name (required):

Your e-mail address (optional, will only be used to inform you when your comment is published
or to respond to your question directly):

Your request or comment (max 2000 characters):

To post VBA code in your comment, use [VB] tags, like this: [VB]Code goes here[/VB].

I give permission to process this data and display my name and my comment on this website
according to our Privacy Policy.

Submit Comment

Jan Karel Pieterse info@jkp-ads.com


Copyright 2023, All rights reserved.
Products | Services | Downloads | Article index | Links | Contact | Newsletter

https://jkp-ads.com/Articles/excel-modern-userform.asp 10/10

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy