GUI is the acronym for Graphical User Interface. The GUI is the part of the program that the user interacts with. A GUI is made up of controls. These controls can be used in a Form. The following table shows some of the most commonly used GUI controls in VBA.
S/N | Control | Description |
1 | Command | Used to execute code |
2 | Combo Box | Used to present a drop down list to the users |
3 | CheckBox | Used for true or false values. Multiple check boxes can have true value at the same time. |
4 | List Box | Used to present a simple list to the users |
5 | Text Box | Used to accept user input |
6 | Scroll Bar | Used for to provide a scrollbar for navigation purposes. |
7 | Spin Button | Used to increment or decrease numeric values by clicking on up or down arrows that appear in the spin button |
8 | Option Button | Used for true or false values. Only one option button can have a true value at a time. |
9 | Label | Used to display static text to the user |
10 | Image | Used to display images |
11 | Toggle Button | Button that has pressed and un-pressed states. |
In the GUI control,
You will get the following drop down panel
If you hover the mouse over control, the name of the control will appear as shown below
We will now add a command button to our workbook, for that we have to
We will now set the caption of the button to something more descriptive
Close the window when you are done.
You will get the following results.
In this section, we will see how to incorporate 'commandclick' button in VBA and execute a program using the button.
Step 1) In this step, click the option "insert button" from the Active X Control. Then select the command button option from it.
Step 2) To insert "clickcommandbutton1" drag the mouse cursor to Excel sheet.
Step 3) Then right click on the command button and select option "View Code".
Step 4) Check you are on the right sheet. A code editor will open. Enter your code.
Step 5) In next step, save code file and then exit the editor. To return to the Excel file click the Excel sheet icon on the extreme left.
Step 6) In Excel sheet, you will see Design Mode tab is on. Make sure it is "OFF" or else your code will not work.
Step 7) When design mode is off, there will be no green highlight on it. Now you can Click on the command button.
Step 8) Click on "CommandButton1". It will print "Guru99 VBA Tutorial" in the cell range "A1 to A10".
As we see in previous tutorial, make sure your ribbon will have "Developer" icon as shown here.
Now, rename sheet1 to "VBA Operator" as shown in screen-shot below. Save the workbook in an Excel Macro-Enabled Workbook (*.xlsm) file extension. (see the image below).
After that, click on Save button.