1 My goal in this lesson is for you to design a form, understand and set the properties placed in the form..
- Microsoft Excel
- Microsoft Word
- R, RStudio
- Packages
- devtools
- knitr
- rmarkdown
- YAML
- MiKTeK
- LaTeK
- CSS
- Paint.Net
- Sublime Text 2
- Regular Expressions
- XML
- HTML
- Google Chrome
- XPath
- DOM
- Bootstrap
It’s okay I’m not expecting you to know any of that, I’m just giving credit to the tools I used.
There will be less explanations in this lesson and more hands on instructions so you will see more terms like click, select, type, enter, etc..
Also Note: There are a few questions in the quiz where you have to look beyond this lesson for the answer.
1.3 For those who haven’t taken lesson 01 open up Excel and in cell G8 of sheet1 type: What is your name?.
Before I begin to take you on this journey, I would like to address a question that is often asked of me when I teach VBA: “If you teach what you know then what use will they have of you?” This question takes me back to my days working at Wal-Mart and walking and talking with Mahmoud, the Asst Store Manager. I was just the guy who threw (unloaded) the truck, but I wanted to learn more so I sought out and learned the Telson (a laser gun with a bunch of information on store products). I asked Mahmoud: why don’t we teach all the employees to make our store a more powerful store and make it better for the customer because everyone will be able to help the customer? Mahmoud’s response to me was: “If I teach them all everything I know then what good am I?”
I have never really cared for that logic. First of all I see programming as an art. I look at someone’s code as another would look through paintings in a museum. Each programmer develops their own style. And, even as you learn every tool, method, and function, you will still have to use your imagination to create. So young artists, let’s begin!
From the Menu bar select Insert and then…
select Userform from the list.
M Y _ u f.
(When renaming your modules and userforms it is a good idea to give them names that are related to content)UserForm1
to
The toolbox is usually nearby the userform but if you’re using two monitors, you might find it over on the other monitor. Here is a picture of it, so you will know what to look for.
Per member feedback: When you click on your UserForm the toolbox appears and when you deselect the UserForm it disappears. You can minimize other windows that you may have open and try selectiong the UserForm again. You can also see if it is visible by selecting View from the menu and then look for Toolbox on the list of menu items. If the icon next to the word Toolbox is greyed out then it is not visible and will not be visible even if you select the UserForm. If this happens you can then select Toolbox from the menu and it will be visible again. There is also another way that you can toggle the visibility on the Toolbox.
Oh you thought I was going to tell you the other way?
Note: a the commandbutton is the same as any other command button you’ve used in windows where you push the button and an action happens as a result. Sure, I know you all know what a button does in computers. I’m really just using this note to add some distance from the one mouse above and the mouse below. Notice this upcoming mouse is donning a hardhat. You guessed it, this mouse, while working on userforms, is going to put in a lot of work.
Now let’s set the properties for the button.
Before you can set the button you have make sure the button is selected or else the properties for the button will not display.
Across the column from (Name) change CommandButton1 to cmdGetQuestion.
Look along the left column for Left and across from it replace the number in the right column with 282
Now look for Top in the left column and replace the number across from it with the number 240.
Look for Caption on the left column and across from it change CommandButton1 to Push button to receive a question and hit Enter.
You cannot see all of the words, right? Okay, let’s fix that.
Make sure the Label is selected and find the properties window.
21. Look for the word Top in the left column and change the value in the right column to the value 12.
By default the value across from word wrap should be set to True
Hover your hard working over the toolbox and Click on the Combobox.
Click on an available space on the UserForm.
Make sure combobox is selected
Now look for the word Width in the left column and replace the number on the right with 168.
Find the ToggleButton button on the Toolbox and Click it.
Hover the over any open area in the MY_uf form and Click the left mouse button.
Once again, remember to make sure the toggle button is selected in order to access the properties for it.
Let’s put the toggle button in a good place
We’re almost finished designing the form, but we need to add just one more button. When you open the form you will need to be able to close the form, so we need to add a Close button.
By default the Project Explorer is the upper left window of the Visual Basic Editor. These windows are docked (locked in place) but can be undocked and moved around. If the project window is not visible, you can. . .
In the Properties window you can customize the name of the module.
I like to give mine short names and sometimes descriptive names. For this lesson we will name the module MYMOduLE, why not?
You will see that the Project Explorer instantly updated the name of the module.
You “SHOULD” see a blank workspace with two dropdown menus right above your workspace; one reads (General) and the other reads (Declarations) as shown in the figure below. The dropdown with (General) at the top of the windows keeps a list of your Objects and the one that reads (Declarations) holds a list of the Object’s Procedures.
Sub ANYNAME
Load MY_uf
MY_uf.Show
End Sub
Notice the space above the code. I usually like to leave a little room to entering more code. You can do this at any time, but I normally like to leave space between subs (and functions). After you enter your Sub name and hit Enter an opening and closing parenthesis will appear after the name and End Sub will appear on the next line giving you a line inbetween to write your code (see the description below)
![]()
There are several ways that you can get to the form’s workspace. Right now we will explore one of the different ways to get to the code area for the form.
Right above the work area Click the dropdown on the left that displays the word (General).
From the dropdown list select cmdClose as described in figure below.
Private Sub cmd_Close_Click()
End Sub
Private Sub cmd_Close_Click()
MY_uf.Hide
Unload MY_uf
End Sub
For Questions and Feedback: earllamontmontgomery@gmail.com