How to Transfer Data From a Tree View Node to Excel

Updated July 20, 2017

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.

Cite this Article A tool to create a citation to reference this article Cite this Article

About the Author

Jaime Avelar is a professional writer whose programming articles appear on various websites. He has been a software programmer since 2000. Avelar holds a Master of Science in information systems from the University of Texas at Arlington.