Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Chip!
1) Leafnode: It works now! 2) Unique key: Not yet, I got "run-time error '35601': Element not fount" at the statement "Set Nd = .Nodes(KeyName)" Please, more advice! br Jim "Chip Pearson" skrev i melding ... 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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorry, my fault :-(
I don't know/remember how and why, but I in one way or another missed the statement "On Error Resume Next". Your sample code for testing if KeyName exists works! Thanks again, Chip! br Jim "JimAnAmateur" skrev i melding ... Thanks Chip! 1) Leafnode: It works now! 2) Unique key: Not yet, I got "run-time error '35601': Element not fount" at the statement "Set Nd = .Nodes(KeyName)" Please, more advice! br Jim "Chip Pearson" skrev i melding ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
TreeView | Excel Programming | |||
TreeView Help | Excel Programming | |||
Treeview | Excel Programming | |||
How to Treeview in VBA | Excel Programming | |||
TreeView | Excel Programming |