Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Treeview - setting node font / bold

Posted on 2012-04-02
9
Medium Priority
?
906 Views
Last Modified: 2012-04-02
Hi there,

I am trying to compare a node key in my treeview control (Excel 2010) to a value in a range. If the two values match, then make the node bold.

I am using the following piece of code:

Private Sub Highlight_Tree(ByVal highlight_node As Object)
' Parentnode previously declared as node - had to change to avoid type mismatch error.
Dim row As Range
Dim rngcomments As Range
Dim wkscomments As Worksheet
Dim n As Object
Set wkscomments = ThisWorkbook.Worksheets("Comments")
Set rngcomments = wkscomments.Range("Comments")

        Do Until highlight_node Is Nothing
            For Each row In rngcomments.Rows
                Debug.Print row.Columns(1).Value, highlight_node.Key
                If row.Columns(1).Value = highlight_node.Key Then
                    With highlight_node.Font
                        .Bold = True
                    End With
                    Exit For
                End If
            Next row
            
            Highlight_Tree highlight_node.Child
            Set highlight_node = highlight_node.Next
        Loop
End Sub

Open in new window


I works all the way up to setting the With highlight_node.Font property, when I get the error:
Object doesn't support this property or method.

Can anyone give me a push on this one ?

Thanks and regards,

Craig.
0
Comment
Question by:slobber72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 37794857
Nodes do not have a Font property. They do however have a Bold property... ;)
0
 

Author Comment

by:slobber72
ID: 37795340
Hi rorys,

Well I changed my code but I'm still getting the same error.

Do Until highlight_node Is Nothing
            For Each row In rngcomments.Rows
                Debug.Print row.Columns(1).Value, highlight_node.Key
                If row.Columns(1).Value = highlight_node.Key Then
                    highlight_node.Bold = True
                    Exit For
                End If
            Next row
            Highlight_Tree highlight_node.Child
            Set highlight_node = highlight_node.Next
        Loop

Open in new window


The line "highlight_node.Bold = True" is where the error is occurring...

Any thoughts ? I don't understand when to use with... for each.... etc with regards to properties and methods.

Cheers,

Craig
0
 
LVL 31

Expert Comment

by:gowflow
ID: 37795357
Seeing no response from asker and not for points just to clarify, rorya meant for you to
replace this
With highlight_node.Font
     .Bold = True
End With

by this
With highlight_node
     .Bold = True
End With

gowflow
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:gowflow
ID: 37795367
Just noticed that we posted at the same time did not see your post first.

I suggest you simply remove from your original code the .Font and give it a try.
gowflow
0
 

Author Comment

by:slobber72
ID: 37795392
Ok - tried that but still the same error.

I am passing the treeview.nodes(1) parameter to the highlight_node procedure .

Would there be an issue here with passing NODES to a procedure and then trying to change the NODE.bold property ?
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 37795419
No - it works fine for me. Is there a reason why you are passing the node As Object rather than As Node?
0
 

Author Comment

by:slobber72
ID: 37795483
Yes - setting

(highlight_node as node)

gives a "type mismatch" error when passing treeview.nodes(1) to the procedure.

setting it to object eliminated the error. But I can't get this to work at all. I have attached a copy of the entire spreadsheet. Maybe I am missing a reference ? This is driving me crazy.
Menu-Documentation-V1.0---Copy.xlsm
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 total points
ID: 37795528
Can you replace your Treeview control version 5 with version 6? I don't have version 5, which is what you appear to be using, so the treeview simply gets removed. This may be part of the problem, since you also have a reference to version 6 of the common controls.

When I do that, the code works - see attached version.
Menu-Documentation-V1.0---Copy.xlsm
0
 

Author Comment

by:slobber72
ID: 37795569
Thank you rorys.

I thought  - I really thought I had a version 6 treeview control. And I never thought to look at that.

This is a great relief.

Cheers,
Craig
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question