VBA – VBA class modules for buttons

Code reusability is important in any programming language. The main idea is to write as little as possible for easier maintenance. And, as it sometimes happens, writing less is much more difficult, than writing a lot. In the current article, I will present how to check the name of the selected buttons just with a few lines of code, using class modules.


The main idea is to create two classes – one called clsChecker and one clsUfClass. In these, we write the following:

The idea is that the first class returns a message box with the caption of the button and its status (selected or deselected) and the second one returns just the name of the radio button.

Thus, we should simply initialize these classes, once the user form is loaded. This is how it happens:

The main idea is that this way we assign the click values to the corresponding buttons just with a simple loop. Once it is set, then it stays 🙂 And we may use it as long as the form is loaded.

Enjoy it! 🙂

Tagged with: ,