Jim,
If by "leafnode" you mean a node with no children, use something like the
following. The second half of the code will test if a key is in use.
Dim Nd As MSComctlLib.Node
Dim KeyName As String
On Error Resume Next
''''''''''''''''''''''''''''''
' Test if SelectedItem has
' at least one child.
''''''''''''''''''''''''''''''
With Me.TreeView1.SelectedItem
Err.Clear
Set Nd = .Child
If Not Nd Is Nothing Then
MsgBox "Item: " & .Text & " has at least one child."
Else
MsgBox "Item: " & .Text & " has no children"
End If
End With
''''''''''''''''''''''''''''''
' See if KeyName exists.
''''''''''''''''''''''''''''''
KeyName = "TestKeyName"
With Me.TreeView1
Set Nd = Nothing
Set Nd = .Nodes(KeyName)
If Nd Is Nothing Then
MsgBox "Key not found"
Else
MsgBox "Key found"
End If
End With
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
"JimAnAmateur" wrote in message
...
I am working on a macro to build/use a TreeView for
structuring/viewing/editing
the content in an Excel file (Excel 2003).
Two questions I hope you experts out there may help me with:
1) How to determine if a node is a leafnode?
2) How to determine if a key is not already in use and thus unique (new
node)?
Jim