Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Leafnode and key in TreeView?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Leafnode and key in TreeView?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Leafnode and key in TreeView?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Leafnode and key in TreeView?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
TreeView Stephen[_22_] Excel Programming 2 October 10th 05 06:25 PM
TreeView Help Tony Excel Programming 0 September 21st 05 05:39 PM
Treeview Patrick Choi[_2_] Excel Programming 1 September 6th 04 08:29 AM
How to Treeview in VBA kvenku[_9_] Excel Programming 1 May 27th 04 01:03 PM
TreeView marijan glavac[_2_] Excel Programming 2 April 30th 04 07:28 AM


All times are GMT +1. The time now is 10:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"