Treeview on a sheet

P

PatrickS

I've added a treeview to a sheet in excel, but I'm having problems using the
ImageList control to store and show images in the treeview control. I'd
successfully managed to get this to work when using it in a dialog, but
unfortunately this is not the case when it exists on a sheet rather than
within a form (this is within excel 2003 BTW)

Does anybody here know how to use imagelists with treeviews when the
treeview and imagelist exists on a sheet?
 
P

PatrickS

I neglected to show the line of code that isn't working:

Set ThisWorkbook.Sheets("Sheet1").OLEObjects("tvContents").Object.ImageList
= ThisWorkbook.Sheets("Sheet1").OLEObjects("ImageList").Object

(ImageList and tvContents obviously being the name of the image list and
treeview control respectively)
 
M

michelxld

Hello Patrick

i hope this helps you



Dim k As Byte, j As Byte
Dim Img1 As String, Img2 As String

Sheets(1).ImageList1.ListImages.Clear
Sheets(1).TreeView1.Nodes.Clear

Img1 = ThisWorkbook.Path & "\LeChat.bmp"
Img2 = ThisWorkbook.Path & "\2053851.jpg"

Sheets(1).ImageList1.ListImages.Add 1, "Image1", LoadPicture(Img1)
Sheets(1).ImageList1.ListImages.Add 2, "Image2", LoadPicture(Img2)

Set Sheets(1).TreeView1.ImageList = Sheets(1).ImageList1

For k = 1 To 5
Sheets(1).TreeView1.Nodes.Add , , "maClé1" & k, "ParentNode" & k,
"Image1", "Image2"
Next

For j = 1 To 5
For k = Sheets(1).TreeView1.Nodes.Count To
Sheets(1).TreeView1.Nodes.Count + 2
Sheets(1).TreeView1.Nodes.Add "maClé1" & j, tvwChild, "maClé2" &
Str(k), _
"ChildNode" & k, "Image1", "Image2"
Next
Next


regards
michel
 
P

PatrickS

Thanks for that, but it's not working for me. I had to change the code anyway
as I don't have the option of storing the images externally, so using
LoadPicture is not possible in this case unfortunately. The images are stored
on one sheet and the code I'm uising ATM is this:

sub BuildImageList()
Dim i As Integer
Dim ws As Worksheet
Dim arrObjName

Set ws = ThisWorkbook.Sheets("Sheet2")
ws.Visible = xlSheetVisible
arrObjName = ws.Range("AE10:AE13").Value

ws.OLEObjects("TreeviewImages").Object.ListImages.Clear
For i = 1 To 4
ws.OLEObjects("TreeviewImages").Object.ListImages.Add Key:="img" &
i, Picture:=ws.OLEObjects("Image" & i).Object.Picture
Next
Set ThisWorkbook.Sheets("Sheet1").tvContents.ImageList =
ThisWorkbook.Sheets("Sheet1").TreeviewImages
Set ws = Nothing
End Sub

I used your syntax when it came to assigning the image list, but it came
back with the 'object does not support property or method' error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top