VBA treeview loading issue - invalid key

孤街浪徒 提交于 2020-01-06 19:54:11

问题


I want to display the Excel data in treeview but it is showing invalid key. Please assist me.

Dim rTWData As Range
Dim oRow As Variant
Dim onode As Variant
Dim lastrow As Integer

Dim myFileNameDir2 As String
Dim ws12 As Worksheet
Dim i2 As Integer
Dim lastrow2 As Integer
Dim filecheck As Variant

myFileNameDir2 = Sheet1.Range("V5").Value
Workbooks.Open Filename:=myFileNameDir2, UpdateLinks:=0
Set ws12 = Worksheets(1)
lastrow = ws12.Range("A" & Rows.Count).End(xlUp).Row - 1
Set rTWData = ws12.Range("A2:L" & lastrow)
With TreeView1
    Set onode = .Nodes.Add(, , "root", "+")
    onode.Expanded = True
    For Each oRow In rTWData.Rows
        .Nodes.Add "root", tvwChild, oRow.Cells(1, 1).Value, oRow.Cells(1, 1).Value
        .Nodes.Add oRow.Cells(1, 1).Value, tvwChild, oRow.Cells(1, 2).Value, oRow.Cells(1, 2).Value
        .Nodes.Add oRow.Cells(1, 2).Value, tvwChild, oRow.Cells(1, 3).Value, oRow.Cells(1, 3).Value
        .Nodes.Add oRow.Cells(1, 3).Value, tvwChild, oRow.Cells(1, 4).Value, oRow.Cells(1, 4).Value
    Next
End With

回答1:


One of the oRow.Cells is empty or is a number.

The key must be a string (must contain a non-numeric character).



来源:https://stackoverflow.com/questions/41505565/vba-treeview-loading-issue-invalid-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!