Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Treeview on a sheet
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? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Treeview on a sheet
I neglected to show the line of code that isn't working:
Set ThisWorkbook.Sheets("Sheet1").OLEObjects("tvConten ts").Object.ImageList = ThisWorkbook.Sheets("Sheet1").OLEObjects("ImageLis t").Object (ImageList and tvContents obviously being the name of the image list and treeview control respectively) "PatrickS" wrote: 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? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Treeview on a sheet
Also neglected to add that the error I was getting was 'Invalid object'.
"PatrickS" wrote: I neglected to show the line of code that isn't working: Set ThisWorkbook.Sheets("Sheet1").OLEObjects("tvConten ts").Object.ImageList = ThisWorkbook.Sheets("Sheet1").OLEObjects("ImageLis t").Object (ImageList and tvContents obviously being the name of the image list and treeview control respectively) "PatrickS" wrote: 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? |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Treeview on a sheet
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 -- michelxld ------------------------------------------------------------------------ michelxld's Profile: http://www.excelforum.com/member.php...o&userid=17367 View this thread: http://www.excelforum.com/showthread...hreadid=538037 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Treeview on a sheet
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, Pictu=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. "michelxld" wrote: 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 -- michelxld ------------------------------------------------------------------------ michelxld's Profile: http://www.excelforum.com/member.php...o&userid=17367 View this thread: http://www.excelforum.com/showthread...hreadid=538037 |