Click to See Complete Forum and Search --> : VB- ComboBox
Greyskull
Jan 12th, 2004, 06:55 AM
Sub Dropdown1_Change()
Dim s As String
Select Case Cells(1, 1).Value
Case 1
s = "C:\1.jpg"
Case 2
s = "C:\2.jpg"
End Select
ActiveSheet.Pictures.Insert s
End Sub
Can anyone make this code any simpler for having a ComboBox with pictures.
Thanx,
Greyskull:) ;)
alex_read
Jan 16th, 2004, 08:57 AM
Well either of these are simpler in as much as less coding but I'd go with what you've got there to be honest - it'd perform just as well ...
Sub Dropdown1_Change()
Select Case Cells(1, 1).Value
Case 1
ActiveSheet.Pictures.Insert = "C:\1.jpg"
Case 2
ActiveSheet.Pictures.Insert = "C:\2.jpg"
End Select
End Sub
or
Sub Dropdown1_Change()
IF (Cells(1, 1).Value = 1) or (Cells(1, 1).Value = 2) then
ActiveSheet.Pictures.Insert = "C:\" & cstr(Cells(1, 1).Value) & ".jpg"
End If
End Sub
debbie_82
Jan 30th, 2004, 01:14 AM
Your code is really neat... I could learn a lot from it...
Madboy
Mar 6th, 2004, 04:45 PM
Any idea on loading these through Image List?
HardCode
Mar 15th, 2004, 03:08 PM
Sub Dropdown1_Click()
ActiveSheet.Pictures.Insert "C:\" & Dropdown1.ListIndex & ".jpg"
End Sub
It may not be Dropdown1.ListIndex. It may be .Index or one of the other properties that gives the Index of the selected item in the Combo Box. Check it out. Also, check to make sure that the Index starts at 1. If not start naming your pics "C:\0.jpg"
kleinma
Apr 6th, 2004, 03:43 PM
Originally posted by HardCode
Sub Dropdown1_Click()
ActiveSheet.Pictures.Insert "C:\" & Dropdown1.ListIndex & ".jpg"
End Sub
It may not be Dropdown1.ListIndex. It may be .Index or one of the other properties that gives the Index of the selected item in the Combo Box. Check it out. Also, check to make sure that the Index starts at 1. If not start naming your pics "C:\0.jpg"
the ItemData property of the combo box is perfect for this... ItemData holds an integer value which can be any type... so you dont have to rely on the index which has to be ordered... you can have duplicate ItemData values... etc... and you can assign a value to a newly added item in the combo by referencing
Combo1.ListData(Combo1.NewIndex) = 10
its real good for when you want text data in a combo to correspond to an ID number in a database...
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.