Вы находитесь на странице: 1из 4

4/7/2015

Design the Treeview User Form

Excel VBA Programming


Home
Getting Started
8 part section >>
VBA Programming Variables
6 Part Section >>
Conditional Logic
9 part section >>
Strings and String Functions
8 Part Section >>
Programming Loops
4 Part Section >>
Programming Arrays
4 Part Section >>
Subs and Functions
6 Part Section >>
Excel VBA and Text Files
2 Part Section >>
Excel VBA and User Forms
5 Part section >>
An Excel Picture Viewer Project
6 Part Section >>
Excel VBA and Charts
4 Part Section >>
A TreeView Project
TreeView Introduction
Designing the UserForm
Parent Nodes and Child Nodes
The Initialize Event
Adding the Child Nodes
The Node Click Event

http://www.homeandlearn.org/design_the_user_form.html

1/4

4/7/2015

Design the Treeview User Form

Design the User Form

Excel Data Analysis


5 Ways to Enhance Excel Data. Download the Free Whitepaper!

Open up the spreadsheet you download in the previous section. Make sure you have saved the file as
a Macro Enabled Workbook. Now click on the Developer ribbon at the top of Excel. Click on Visual
Basic in the Coding panel to open up the VBA Editor.
When your editor opens, click on Insert > User Form from the menu bar at the top.
In the properties panel for the new form, change the Name property to Nations. Locate the Caption
property and change it to Nations.
In the VBA toolbox locate the Treeview control:

http://www.homeandlearn.org/design_the_user_form.html

2/4

4/7/2015

Design the Treeview User Form

Draw a Treeview onto your form. Draw it on the left, and then use the resizing handles to make it a
decent height. Make it wide enough for some text, but not too wide.
With your Treeview selected, change the following two properties:
LineStyle: tvwRootLines
Style: tvwTreeLinesPlusMinusText
You Treeview should look like this when you're done:

Notice that the default parent and child nodes just say "Sample Node". We'll change these defaults
with code.
Add 5 labels to the right of your Treeview. Change the Caption properties to: Populations (in millions),
Life expectancy, Currency, Capital, and Fun Facts. Add four more labels to the right of the first four
labels. You can change the style of your labels. Experiment with the following properties of labels:
BorderStyle, BorderColor, BackColor, Font.
Now add a textbox just below the Fun Facts label. Just below the textbox, add a Command Button.
Change the Caption property to Exit.
Your form in design view should look something like ours below:

http://www.homeandlearn.org/design_the_user_form.html

3/4

4/7/2015

Design the Treeview User Form

In the next part, we'll make a start on the code.


Adding Nodes to a Treeview >>

Lots more free online course here on our main Home and Learn site
All course material copyright Ken Carney

http://www.homeandlearn.org/design_the_user_form.html

4/4

Вам также может понравиться