How to Transfer Data From a Tree View Node to Excel

Written by jaime avelar | 13/05/2017
How to Transfer Data From a Tree View Node to Excel
User Visual Basic to create a new workbook. (Ryan McVay/Photodisc/Getty Images)

Being able to export tree view node information to Excel can make your application more dynamic. In Visual Basic, you can get text from a selected node in a tree view control by using the "SelectedNode" property. This property represents the selected node in the tree view which you can use to obtain the data in the node. Use the Microsoft Excel Object Library to create a new workbook and export the data to one of its worksheets.

Launch Microsoft Visual Basic Express and select "New Project..." from the left pane of your screen. Click "Visual Basic" under "Installed Templates" and double-click "Windows Forms Application."

Click the "Toolbox" pane and double-click "TreeView" to add a new "TreeView" control to your form. Double-click "Button" to add a new button to transfer data from the "TreeView" control.

Click the "Project" menu and select " Properties." Click "References," then select "Add." Select "COM" and click "Microsoft Excel Object Library." Click "OK."

Double-click the form to create a form load event and add the following code to add three nodes to the tree view control:




Double-click "Button1" to create a click event for the button and add the following code to create a new Excel file and add the selected node text to "A1":

Dim xlTV As New Excel.Application

Press "F5" to run the program and select a node in the tree view control. Click "Button1" to create the Excel file.

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.