3 My goal in this lesson is to show you the fun side of programming by showing interesting relatable examples at the same time building a project.
- 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
- PyCharm Community Edition 4.5.4
- Python
- re (regular expressions)
- sys, os
Okay I don’t want to be this guy
but I have to say it: open your file that you created in Lesson 01 –
One way: Select the Developer ribbon and Click the Visual Basic button located all the way to the left on the ribbon…
OR
the other way: On the keyboard press Alt 11
If you have a grey background in your workspace when you open your Visual Basic Editor (VBE) follow these steps:
From the VBE there are four (4) different ways to view the MYMOduLE code. For now we will press the F7 key on your keyboard.
It expresses the concepts of determination, will power and belief. When I sit down in front of a computer to program, the advantage that I have is that I totally believe that I will succeed.
your initials, an underscore and lesson_03, at this point I believe you don’t need step by step instructions to do that part. (for me the file would look like this: ELM_lesson03.xlsm)
I have decided to go over, step by step, a piece of one of the projects that I created and a piece of one that I am currently working on. The first one that I will go over is a section of a project called
No Show/Action Required (NSSP)
A brief description of this Add/Remove Auxillary Email Dialog Box (UserForm).
The Gold colored EXIT button, closes the UserForm. Below that is a comboBox that lists all the Clinics in the workbook. The listBox below and to the left displays a list of emails for the selected clinic. The commandButton below that listbox removes the selected email from the list and adds it to the listBox on the right as emails that have been removed. Under the big, bold OR is a comboBox where the user can type in an email to the auxillary list. After you are satisfied with all of your updates, the user can then click the bottom commandButton to update all the sheets.
Whenever you’re getting ready to start a project, it’s a good idea to write out what it is that you want to do and how you are going to accomplish it. If you have a form, design the form on paper first. This is good practice.
Your sheet names:
* START_PAGE
* FIRST_SHEET
* SECOND_SHEET
* THIRD_SHEET
* LOGIC
If you look in the Homage section, you will see that I have added PyCharm Community Edition. I used Python code to create the email lists that we will use with this project.
In cell F2 on the sheet named FIRST_SHEET copy and paste the following list to that cell.
Harry.Heryum@ittagin.com; Craspe.A@medusa.com; Electric.B@teries.com; Dot.dot@line.com; Ra.Er@sayitagain.org; En.Horax@bugsme.com; Eppy.Ick@granite.org; Little.Cree@Ure.edu; Hydrous.Silicl@Ess.mil; Tu.The@mosphere.mil; Cindy.Smorgeshborg@org.com; The.Fan@Icks.com; Leppy.Ed@slanging.com;Pe.Rofi@feedthekids.com; Macroleppy.Um@magicmushroom.com;
In cell F2 on the sheet named SECOND_SHEET copy and paste the following list to that cell.
Cindy.Smorgesh@borg.org; The.Spect@Or.org; Al.Iswell@thehomestead.edu; Haleci.A@tessellaris.edu; Thermanti.Es@Rotatingfans.org; Psue.Suga@douglasfir.com; To.The@Mosphere.mil; Ri.To@myprivatevenice.org; Tail.Fe@Hers.org; A.Mul@Toe.com; To.Zar@Hustra.com; Po.Heca@scalyfoot.com; Macacus.Pile@Us.gov; Sacer.Al@wheresmypriest.com; Extra.Al@itshers.com; En.Helium@scottiestissue.com; Heru.Us@historians.edu;
In cell F2 on the sheet named THIRD_SHEET copy and paste the following list to that cell.
The.Adri@Ic.com; The.Gree@Est.com; Johnny.Walker@Red.com; Pleasantly.Stimul@Ing.org; Sumver.Ovadarenbo@aplaceandtime.com; The.Ultim@E.org; To.Radi@Ion.org; Aceituna.Zap@Era.com; Gona.ropin@fertmeds.com; The.Arom@Ic.com; Dorothy.Tee@definatelydot.com; A.Gradu@Ed.edu; Theo.L@In.com; A.Fan@Ical.com; Paleozoic.Form@Ions.org; Closely.Rel@Ed.edu;
Note: If you have multiple instances of Excel open make sure that you are creating the form within the same workbook.
In the Visual Basic Editor on the Standard Toolbar Click that eeny weeny, tiny, little, down-pointed arrow on the right side of the insert … button. That tiny almost non existent button exposes a dropdown menu to insert a UserForm, Module, Class Module, or Procedure.
Select UserForm. In the Properties window across from the row (name) rename the form AuxEmailForm.
Go back to the Standard Toolbar and back to that eeny weeny down-pointed arrow and this time from the dropdown menu select Module. From the Properties Window rename Module Tools.
In the Properties window select the Categorized tab as shown within the red circle in the picture diagram. This categorizes all the items in the left column.
Scroll to find the section named Position. From there set the Height to 378.75, the Left to 0, the StartUpPosition to 1 - CenterOwner, the Top to 0 and the Width to 341.25 as indicated within the red square in the picture description.
Using the visual description below, see how close you can match the design.
hint: The items consist of:
* 4 Labels,
* 4 commandButtons,
* 2 listBoxes, and
* 2 comboBoxes
Click image for names of items
Double click on any open space inside your form as indicated in the red squared off areas in the diagram below
This will take you behind the scenes to the code area of the userform.
Select and delete those lines from Private Sub UserForm_Click() to End Sub and from the right dropdown window select initialize.
On the empty line between the Private Sub UserForm_Initialize() and the End Sub type the tab key and type dim sh as worksheet. When you type the a in as, a list will dropdown for you to select from. As you type worksheet another dropdown list will appear to help you select your words. Your code should look like the following after you hit enter:
Private Sub UserForm_Initialize()
Dim sh As Worksheet
End Sub
Notice that you typed all lowercase words and when you hit enter certain letters capitalized. This is because they are keywords. You’ll learn more about keywords later. For now let’s examine the Dim. Dim is used to give variables existence. Dim stands for dimension. In this particular case we are dimensioning sh as a worksheet. Normally we would still have to give the variable a value but in this case both the value and the type are set all in one. We will explore more variables and types later.