Design the User Form

 

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:

The Excel VBA toolbox showing a  Treeview control

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:

The Treeview's default nodes

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:

An Excel VBA form with a treeview on the left

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

Adding Nodes to a Treeview >>