Thread: user form image
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default user form image

"Atishoo"

I didnt get you..

--You dont need to write any more code otherthan what is seen below.

--From your original post I understand each number corresponds to a item.
say 1 for apple, 2 for banana and so on..

--The minimum what should you do is refer this to a table to let the code
know which image relates to which number.

--What is impractical. To create the list of 4000 images? Go to command mode
and from DOS within the image directory use the below command to create the
list of image names. suppose you have images in C:\images\. Then open this
txt file in excel as fixed with and create the list of images.. Sort the list
and assign numbers..In the list if you are keeping the extension (.jpg) then
you can take it off from the below code...

c:\images\dir *.jpg 1.txt

If this post helps click Yes
---------------
Jacob Skaria


"Atishoo" wrote:

Thanks
I could do that but with over 4000 images its gonna be impractical I just
need a way to reference the first item in a folder or the third or twenteeth
etc

"Jacob Skaria" wrote:

Hi "Atishoo"

1. Insert a new sheet and name 'PicIndex'
2. Enter the numbers in ColA and its corresponding image name in ColB
starting from row1. Name the range as 'PicList'
3. Use the below code

Dim picPicture As IPictureDisp
Dim strPath as String
Dim strFile As Variant
On Error Resume Next
strPath = "c:\windows\mydocuments\newfolder\"
strFile = Application.VLookup(CInt(TextBox1.Value), Range("piclist"), 2,
False)
Set picPicture = stdole.StdFunctions.LoadPicture(strPath & strFile & ".jpg")
UserForm1.Image1.Picture = picPicture
UserForm1.Show


4. If you dont name the range then refer the full range like
Sheets("PicIndex").Range("A1:B100") in the VLOOKUP formula.

Try and feedback

If this post helps click Yes
---------------
Jacob Skaria


"Atishoo" wrote:

I am wanting to display a variable image in a user form dependant
alphebetically on a number selected in a text box (so if textbox1.value=1
then load picture apple.jpg, if 2 banana.jpg etc I cant just list all the
images as there are going to be somewhere in the region of 4000 total images
in the target folder.

any ideas


cyrrently have it set to just display a sigle image as below.
Dim picPicture As IPictureDisp
Set picPicture =
stdole.StdFunctions.LoadPicture("c:\windows\mydocu ments\newfolder\apple.jpg")

UserForm1.Image1.Picture = picPicture

UserForm1.Show