Thread: user form image
View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Atishoo Atishoo is offline
external usenet poster
 
Posts: 267
Default user form image

Try this I put mine on a command button from the control toolbox.

Private Sub CommandButton1_Click()

For Each c In Worksheets("Sheet1").Range("B:B").Cells
If c.Value < "" Then

With c.Offset(0, 1)
Dim myPict As Picture
Set myPict = .Parent.Pictures.Insert("C:\FolderName\" & c.Value)
myPict.Top = .Top
myPict.Width = .Width
myPict.Height = .Height
myPict.Left = .Left
myPict.Placement = xlMoveAndSize
End With

End If
Next

End Sub


"E Manouchos" wrote:


Dear Jacob
I have seen your suggestion for displaying and inserting images to an excel
file. What I want is this: I have the names of the picture files in column
B.In the next column, I would like to use a macro or a function so that each
picture is inserted automatically in the corresponding cell. The pictures are
in a folder under drive c. Do you have any idea about it. I will appreciate
your prompt reply
"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