How to Transfer Data From a Tree View Node to Excel

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
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.

Skill level:

Other People Are Reading


  1. 1

    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."

  2. 2

    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.

  3. 3

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

  4. 4

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




  5. 5

    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

        xlTV.Visible = True
        Dim xlTVwks As Excel.Workbooks = xlTV.Workbooks
        Dim xlTVwk As Excel.Workbook = xlTVwks.Add
        Dim xlTVshts As Excel.Sheets = xlTVwk.Worksheets
        Dim xlTVsht As Excel.Worksheet = xlTVshts("Sheet1")
        xlTVsht.Range("A1").Value = TreeView1.SelectedNode.Text.ToString
  6. 6

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

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

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