Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Initialising A ImageList object in an Excel User Form

Status
Not open for further replies.

ProjectExplorer

Programmer
Mar 22, 2002
95
GB
I am building an Excel User Form with a ListView object on it. I have also added a ImageList object so that I can have icons appearing in the ListView object. I have used the List View object many times before and usually initialize the ImageList via the "Custom" properties pages.

I cannot seem to do this in Excel (no idea why it won't let me). Does any one know how to initialize the ImageList object in VB code.

Any help please.

Thanks
 
It is rather strange that you can't access '(custom)' properties of imagelist control.

To add picture in a design time you need a reference to 'Microsoft Visual Basic fof Applications Extensibility 5.3' (VBIDE) and the code:
[tt]Dim vbc As VBIDE.VBComponent
Set vbc = ThisWorkbook.VBProject.VBComponents("UserForm1")
vbc.Designer.ImageList1.ListImages.Add , , LoadPicture("C:\Picture.bmp")[/tt]

The detailed description of imagelist in MS KB:

combo
 
Combo

Many thanks for your response. I think I did not describe the problem quite correctly (it was late!).

I have added icons to the ImageList object at design time via it's custom properties. What I cannot seem to do at design time is then go into the custom properties in the ListView object and reference the ImageList object (it simply does not appear in the drop down list). This only occurs when I'm building a user form in Excel, it works fine in Access.

I thought I may be able to get around the problem by referencing the ImageList object to the ListView object at run time (i.e. in code), but I cant figure out how to do this.

I am using a developer edition so there should be no problems using the objects.
 
Sorry, I haven't read your post carefully. AFAIK, you can't see imagelists when they are on VBA userforms (however, they are visible when are on a worksheet).
Hope that one of this code will work (in userform module, runtime, change Icons to SmallIcins if necessary):
[tt]Me.ListView1.Icons = Me.ImageList1[/tt]
or maybe this at design time (with reference to proper VBIDE library, standard module):
[tt]Dim vbc As VBIDE.VBComponent
Set vbc = ThisWorkbook.VBProject.VBComponents("UserForm1")
vbc.Designer.ListView1.Icons=vbc.Designer.ImageList1[/tt]

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top